Re: INSERT... WHERE - Mailing list pgsql-general

From Robert James
Subject Re: INSERT... WHERE
Date
Msg-id CAGYyBgjC63_PbnAwVkm8sh4LSaPMaG6yRRwagqotV=UG-biTFw@mail.gmail.com
Whole thread Raw
In response to Re: INSERT... WHERE  (Ian Lawrence Barwick <barwick@gmail.com>)
Responses Re: INSERT... WHERE  (Chris Angelico <rosuav@gmail.com>)
Re: INSERT... WHERE  (Abel Abraham Camarillo Ojeda <acamari@the00z.org>)
List pgsql-general
On 1/13/13, Ian Lawrence Barwick <barwick@gmail.com> wrote:
> 2013/1/14 Robert James <srobertjames@gmail.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;


Thanks.  But how do I do that where I have many literals? Something like:

INSERT INTO seltest (id, a, b) SELECT (1,2,3),(4,5,6),(7,8,9) WHERE b
IN (SELECT ...)


pgsql-general by date:

Previous
From: Gavin Flower
Date:
Subject: Re: Linux Distribution Preferences?
Next
From: Chris Angelico
Date:
Subject: Re: INSERT... WHERE