[nycphp-talk] PEAR::DB->nextID problems
Mitch Pirtle
mitchy at spacemonkeylabs.com
Tue Aug 3 13:51:28 EDT 2004
Daniel Convissor wrote:
>A couple thoughts off the top of my head... I think the behavior may
>vary between DBMS's. Also, all the system is meant to do is provide a
>unique number, not necessarily a specific number, so it doesn't really
>matter what the number is.
>
>
It does if you are trying to keep that number synced with a sequence LOL
Also, do you know if the other relational databases do that too (DB2,
Oracle, etc.), or is this a PostgreSQL only thing?
>A quick look at your test script shows you're using the PostgreSQL's
>native serial (which is like auto_increment to you MySQL'ers out
>there) and PEAR DB's sequence data. Use one or the other. Using both
>leads to the problems you're seeing, let alone, the duplication of
>information.
>
>
As long as you are aware that nextID() will increment the sequence, you
are golden. This is what confused me, and when I was writing the test
script it dawned on me what was going on. I'm not using PEAR DB's
sequence data, but using DB's nextID() to get the current value from the
sequence in a PostgreSQL database. I've tested it thoroughly enough to
feel confident that this is expected/consistent behaviour (at least on
PostgreSQL).
>>Providing an example
>>in the docs would be a time saver and avoid unnecessary forehead
>>slapping. ;-)
>>
>>
>http://pear.php.net/manual/en/package.database.db.intro-sequences.php
>has an example. Are you saying it's too terse / not real-world
>enough?
>
>
Nope, I love the documentation you have been providing :-) Just would
really like a note for PostgreSQL folks out there that if they want to
use nextID() to deal with existing sequences, they will need to omit the
'_seq' from the sequence name and also use that number for the SERIAL
column if they are issuing DML on that column. Maybe a two table
example where you use the newly created SERIAL column in one table to
update rows in another? I'll supply the text if you want.
Or do I ask too much? :-)
-- Mitch
More information about the talk
mailing list