From: | Abel Abraham Camarillo Ojeda <acamari(at)the00z(dot)org> |
---|---|
To: | Robert James <srobertjames(at)gmail(dot)com> |
Cc: | Ian Lawrence Barwick <barwick(at)gmail(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: INSERT... WHERE |
Date: | 2013-01-15 05:26:51 |
Message-ID: | CAPD=2Nj9GcTAg6MFzYdQHBfUFbAY-TLaZDVx6LM1jam8dFpXdg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Sun, Jan 13, 2013 at 10:37 PM, Robert James <srobertjames(at)gmail(dot)com>wrote:
> On 1/13/13, Ian Lawrence Barwick <barwick(at)gmail(dot)com> wrote:
> > 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;
>
>
> 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 ...)
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>
insert into seltest (id, a, b) select a from (values (1, 2, 3), (4, 5, 6),
...) as t(a, b, c) join t2 on = ...;
From | Date | Subject | |
---|---|---|---|
Next Message | Darren Duncan | 2013-01-15 07:22:18 | Re: INSERT... WHERE |
Previous Message | Jeff Janes | 2013-01-15 04:45:18 | Re: reducing number of ANDs speeds up query RESOLVED |