![]() | |
![]() |
| | Thread Tools | Display Modes |
#11
| |||
| |||
|
|
On Thursday October 28 2004 11:42, Robby Russell wrote: Thanks, this seems to work well. My goal is to actually create a php function that takes a result and returns the insert_id like mysql_insert_id() does, but without needing to know the sequence names and such. I would make a psql function, but I don't always have that option with some clients existing systems. An alternative is to simply select nextval() from a separately-created sequence object to get the serial value, then insert with that value. No need to have a serial column then, but you do need to explicitly create the sequence object, as opposed to SERIAL. |
#12
| |||
| |||
|
#13
| |||
| |||
|
|
But I didn't understand why you care to get rid of the explicit reference to the sequence object in your code in the first place. In PostgreSQL, at least for the past 5 years if not longer, if you create a SERIAL column for (schemaname, tablename, columnname), then your sequence will *always* be "schemaname.tablename_columnname_seq". |
#14
| |||
| |||
|
|
On Thu, Oct 28, 2004 at 04:51:05PM -0600, Ed L. wrote: But I didn't understand why you care to get rid of the explicit reference to the sequence object in your code in the first place. In PostgreSQL, at least for the past 5 years if not longer, if you create a SERIAL column for (schemaname, tablename, columnname), then your sequence will *always* be "schemaname.tablename_columnname_seq". Only for certain values of "always." Tables and columns can be renamed, so the sequence name might no longer be "tablename_columnname_seq", but rather "oldtablename_oldcolumnname_seq". |
#15
| |||
| |||
|
|
In PostgreSQL, at least for the past 5 years if not longer, if you create a SERIAL column for (schemaname, tablename, columnname), then your sequence will *always* be "schemaname.tablename_columnname_seq". If that naming convention changes, there will be a whole lotta breakage world-wide. |
#16
| |||
| |||
|
|
"Ed L." <pgsql (AT) bluepolka (DOT) net> writes: In PostgreSQL, at least for the past 5 years if not longer, if you create a SERIAL column for (schemaname, tablename, columnname), then your sequence will *always* be "schemaname.tablename_columnname_seq". If that naming convention changes, there will be a whole lotta breakage world-wide. I hope you're wrong about people expecting that to be true because it isn't. The resulting sequence name is limited to 63 characters and gets truncated if it goes over. (63!? was it intended to be 64?) I believe the limit used to be 32 characters too. |
![]() |
| Thread Tools | |
| Display Modes | |
| |