From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Abdul-wahid Paterson <aw(at)lintrix(dot)net> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: foreach statment? |
Date: | 2003-05-20 00:33:24 |
Message-ID: | 24945.1053390804@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Abdul-wahid Paterson <aw(at)lintrix(dot)net> writes:
> I would do something like this:
> select i.item_id from items i where (select count(item_id) from
> items_options where item_id=i.item_id) = 0;
> And then write a script that will go through the outputted list of
> item_id's and for each one do an insert statement like:
> insert into items_options values ($item_id, $n);
> Where $n is the number of my default option.
Use INSERT/SELECT:
insert into items_options
select i.item_id, $n
from items i where (select count(item_id) from
items_options where item_id=i.item_id) = 0;
BTW, I'd think about a NOT EXISTS instead of a COUNT test in the
WHERE ... should run faster ...
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Larry Rosenman | 2003-05-20 00:33:49 | Re: pg_atoi problem with 7.3.2 |
Previous Message | Jim C. Nasby | 2003-05-20 00:33:03 | Re: ERROR: Memory exhausted in AllocSetAlloc(188) |