Re: INSERT... WHERE

From: Ian Lawrence Barwick <barwick(at)gmail(dot)com>
To: Robert James <srobertjames(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: INSERT... WHERE
Date: 2013-01-14 02:29:21
Message-ID: CAB8KJ=he+ZfrRpDEpmxs6Fi5M-t0qYgpJJrAA6vMPu+pvCwVcg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2013/1/14 Robert James <srobertjames(at)gmail(dot)com>:
> I have a lot of VALUES I want to INSERT. But only a subset of them -
> only those that meet a JOIN criteria involving another table.
>
> I could INSERT them into a temp table, and then do a SELECT INTO. But
> do I need to do that? Is there any way to do a INSERT... VALUES ...
> WHERE...

INSERT INTO ... SELECT is what you are looking for.

Simple example:

CREATE TABLE seltest (id INT);
INSERT INTO seltest (id) SELECT 1;

HTH

Ian Lawrence Barwick

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Edson Richter 2013-01-14 02:50:21 Re: Linux Distribution Preferences?
Previous Message Scott Marlowe 2013-01-14 02:22:50 Re: INSERT... WHERE