+2 votes
in Databases by (11.1k points)

I want to insert multiple rows into a PostgreSQL table using a single 'insert into' query. Right now I am inserting as follows:

insert into tperson values (2,'CA')

insert into tperson values (4,'FT') 

insert into tperson values (5,'CA')

How can I insert all values in just one 'insert into' query?

1 Answer

0 votes
by (15.8k points)

In PostgreSQL, you can insert multiple row using one 'INSERT INTO' query. The syntax is as follows:

INSERT INTO table ( Column1, Column2 ) VALUES ( Value1, Value2 ), ( Value1, Value2 ),...

E.g.

=>insert into tperson values (2,'CA'),(4,'FT'),(4,'CA');
INSERT 0 3

...