Re: foreach statment?
| От | Tom Lane |
|---|---|
| Тема | Re: foreach statment? |
| Дата | |
| Msg-id | 24945.1053390804@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | foreach statment? (Abdul-wahid Paterson <aw@lintrix.net>) |
| Список | pgsql-general |
Abdul-wahid Paterson <aw@lintrix.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
В списке pgsql-general по дате отправления: