Alvaro Herrera wrote:
You can create a function to get the sequence name attached to a table.
Of course, you should take into account the fact that there could be
more than one (two serial fields in a table are rare but not
impossible), but if your tables have only one sequence you should be OK.
Are there a way to find and test if it is a primary key ?
Something with
select relname, relkind
from pg_depend join pg_class on (oid = objid)
where pg_depend.refobjid = 'foo'::regclass
and relkind = 'S';
Hmm, need to play more around using the "pg_" system tables.
Are they all well documentet, or need I some guessing ?
(only lightly tested). Then you can use that to construct your argument
to the nextval() function.
:-)
This doesn't happen with sequences on Postgres. The value you get is
guaranteed to be the one the sequence generated for you.
I know, and this is one of the reasons for not using MySQL :-)
/BL
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend