Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgresql multiple insert with select query

i need to perform a insert query for multiple rows whereby the first column is a numeric and identical value and the second values are queried from another table.

something like

insert into table (33, select col2 from another_table);

can this be accomplished with a single statement?

like image 423
alan Avatar asked May 31 '10 16:05

alan


People also ask

How do I run multiple inserts in PostgreSQL?

PostgreSQL INSERT Multiple Rows First, specify the name of the table that you want to insert data after the INSERT INTO keywords. Second, list the required columns or all columns of the table in parentheses that follow the table name. Third, supply a comma-separated list of rows after the VALUES keyword.

What's the fastest way to do a bulk insert into Postgres?

To perform a bulk insert you'd simply createdb and then use csvsql , which connects to your database and creates individual tables for an entire folder of CSVs.

How can I insert multiple records in a SQL table using a single insert statement?

INSERT-SELECT-UNION query to insert multiple records Thus, we can use INSERT-SELECT-UNION query to insert data into multiple rows of the table. The SQL UNION query helps to select all the data that has been enclosed by the SELECT query through the INSERT statement.


1 Answers

like this

insert into table 
select 33, col2 from another_table;
like image 50
SQLMenace Avatar answered Sep 20 '22 16:09

SQLMenace