Two serial numbers in one table

Поиск
Список
Период
Сортировка
От D'Arcy J.M. Cain
Тема Two serial numbers in one table
Дата
Msg-id 200310271605.45432.darcy@druid.net
обсуждение исходный текст
Список pgsql-hackers
Here is what I am trying to do.  I have a table with two fields, both of which 
are supposed to contain a serial number.  The first one is the primary key 
and is setup to default to a sequence in the normal way.  The second one can 
be one of any number of sequences.  The sequence to use is calculated at run 
time and the next sequence is manually included (creating the sequence if 
necessary.)  Sometimes the sequence is left null.  In those cases it is 
supposed to use the first (primary) field.

I suppose I can add a rule on the select but this is a huge and busy table 
with an index and selects on the second field.  I would prefer if I could 
create the actual value value during insert.  I did try this:

ALTER TABLE certificate ALTER COLUMN card_id SET DEFAULT CURRVAL('certificate_certificate_id_seq'); 
This mostly works but it has two problems.  The first is that it seems klugey 
and I am not sure if I can depend on it happening in the correct order.  The 
second problem is that there are edge cases (albeit none that I can imagine 
happening in our application) that causes it to either fail or put a previous 
value into the field.

Is there a better way to do what I am trying to do?

-- 
D'Arcy J.M. Cain <darcy@{druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.


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

Предыдущее
От: Fernando Nasser
Дата:
Сообщение: Multiple database services and multiple versions on Red Hat Linux systems
Следующее
От: Jan Wieck
Дата:
Сообщение: Re: Still a few flaws in configure's default CFLAGS selection