Re: Generate char surrogate key

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: Generate char surrogate key
Дата
Msg-id 200403191948.01298.dev@archonet.com
обсуждение исходный текст
Ответ на Generate char surrogate key  (Josué Maldonado <josue@lamundial.hn>)
Список pgsql-general
On Friday 19 March 2004 19:25, Josué Maldonado wrote:
> Hello list,
>
> Have a table with char(3) column, the column should contain values like
> '001','002','003'... and so on, keys must be correlatives no
> '001','005','007' should be allowed, any idea how to get it done using a
> trigger?

You can lock the table, then do something like:
  SELECT key_column FROM table_name ORDER BY key_column DESC LIMIT 1;
Add one to the value you get and that's the next in order.

Of course that won't help you if there are deletions/renumberings etc.

--
  Richard Huxton
  Archonet Ltd

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: pg_dump on older version of postgres eating huge
Следующее
От: Greg Stark
Дата:
Сообщение: A way to refer to the "outer" query implicitly?