Search Postgresql Archives

Sequences question & problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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...



---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
      joining column's datatypes do not match

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux