I have a table with columns taking default values:
create table indexing_table
(
id SERIAL PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
);
How do I insert multiple default rows into this table? Do I have to repeat the command:
insert into indexing_table default values;
as many times as I want it to be inserted?
When you have a default value, you can tell the database to use this default value:
INSERT INTO indexing_table(id, created_at)
VALUES(default, default),
(default, default),
(default, default);
If you need hundreds of default records and one of your defaults is "now()", use generate_series():
INSERT INTO indexing_table(created_at)
SELECT NOW() FROM generate_series(1,100);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With