How to INSERT INTO one table from another table, WHERE

From: Kirk Wythers <wythe001(at)umn(dot)edu>
To: POSTGRES <pgsql-general(at)postgresql(dot)org>
Subject: How to INSERT INTO one table from another table, WHERE
Date: 2013-05-03 17:51:20
Message-ID: C9FB8B33-B651-4EAF-91E4-EF75EE9A5B84@umn.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am trying to insert data from 2 columns in tableB (colX and colY) into the same two columns of tableB, with a join like where clause. Is this possible?

For example:

INSERT INTO tableA (colX, colY)
(SELECT colX, colY
FROM tableB
WHERE
tableA.blockname = tableB.block_name
AND tableA.timestamp = tableB.timestamp)
;

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Igor Neyman 2013-05-03 18:00:57 Re: How to INSERT INTO one table from another table, WHERE
Previous Message Yuriy Rusinov 2013-05-03 17:44:04 Re: SPI_execute_with_args call