From: | "Lada 'Ray' Lostak" <ray(at)unreal64(dot)net> |
---|---|
To: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Sequences question & problem |
Date: | 2005-05-16 10:29:27 |
Message-ID: | 011801c55a02$238d1490$2206d052@unreal64.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi there,
I am having small trouble with sequences. I am inserting row into table,
and I need to get value of its 'id' column (sequencen type). As far I know
it have to be done by
SELECT last_value FORM seq_name
(or next_val before insert).
Normally, sequences are created by 'table' & 'column' & '_seq' eg.
'table_id_seq'.
Now let's rename 'table' to 'table2'. Sequence name wan't renamed. And it's
my problem... I can't simple assume 'sequence id' by table/column... I see 2
solution:
1. udpate pg_class after renaming. Something like:
UPDATE pg_class SET relname='table2_id_seq' WHERE relname='table_id_seq'
Will this work well for all possible cases ? Is this good way ?
I tried that that and then 'insert' itselfs generates error:
ERROR: Relation "public"."table_id_seq" does not exist
It seems it was looking for OLD sequence name. I used psql for updating,
while postgres was normally running. Is this problem on my side or I can't
simple change 'relname' of pg_class ?
2. make code reading 'sequence names' live. I looked around pg_class but I
am not sure which relation between reltype,relfilenode,reltoastrelid are
proper ones... So, how to get 'sequence name' by its 'table name' ? Name of
sequence and table are not related (we can't assume some prefix in name,
because table was renamed) Will this pg_class reference cost many CPU ?
Thank you,
Best regards,
Lada 'Ray' Lostak
Unreal64 Develop group
http://www.orcave.com
http://www.unreal64.net
--------------------------------------------------------------------------
In the 1960s you needed the power of two C64s to get a rocket
to the moon. Now you need a machine which is a vast number
of times more powerful just to run the most popular GUI.
Imagination is more important than knowledge...
From | Date | Subject | |
---|---|---|---|
Next Message | Himanshu Baweja | 2005-05-16 10:51:16 | Relation between pgsql_tmp and work_mem |
Previous Message | Stefan Hans | 2005-05-16 09:51:38 | UTF-8 and LC_CTYPE locale |