Re: insert with select as value

Поиск
Список
Период
Сортировка
От Harald Fuchs
Тема Re: insert with select as value
Дата
Msg-id pud63q8mh3.fsf@srv.protecting.net
обсуждение исходный текст
Ответ на insert with select as value  (Milos Prudek <prudek@bvx.cz>)
Список pgsql-general
In article <40D96C94.5040005@bvx.cz>,
Milos Prudek <prudek@bvx.cz> writes:

>> If your purpose in doing this is just to generate unique keys, you should
>> be using sequences instead.

> I would need 150 separate sequences, because each idsection needs its
> own, independent sequence of idthread.

What you really seem to need is a counter for each idsection.
Depending on how often you need to access the counter value, it might
be worthwile to not store the count at all and instead use a single sequence.
You can compute the counter value at SELECT time by something like

  SELECT idsection,
         ( SELECT count (*)
           FROM tbl t
           WHERE idsection = tbl.idsection
             AND id <= tbl.id
         ) AS idthread
  FROM tbl

where "id" is the single sequence.

В списке pgsql-general по дате отправления:

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: psql
Следующее
От: "Antony Paul"
Дата:
Сообщение: timestamp without time zone format