[UPHPU] Postgres Insert ID
Joseph Scott
joseph at randomnetworks.com
Wed Oct 22 17:00:44 MDT 2008
On Oct 22, 2008, at 3:20 PM, Sean Thayne wrote:
> Thanks, that's a bummer, wonder by Postgres doesn't have a feature
> like
> this. Don't most database servers have a equivalent function?
It's just done differently. Instead of making the auto number feature
a column attribute, it's done as a separate object (called a sequence).
In MySQL you'd follow something like this:
- Insert new data
- Ask for the auto number ID for the data we just inserted
In PostgreSQL (and any other DB that uses sequences, like Oracle) the
order would be switched:
- Ask for a new auto number ID from the sequence
- Insert the new data, using the ID we got from the sequence
That said it's pretty common in PostgreSQL to make an auto number
field who's default value is to select the next number from the
sequence.
--
Joseph Scott
joseph at randomnetworks.com
http://joseph.randomnetworks.com/
More information about the UPHPU
mailing list