Link to home
Start Free TrialLog in
Avatar of aolXFT
aolXFT

asked on

'auto_increment' in PostgreSQL

Hi

I'm working on converting a PHP/MySQL application to a PHP/PostgreSQL app.

I need help with the auto_increment.

I've read through the source code of a few scripts that support MySQL, and PostgreSQL, and noticed that they overcame the problem using Sequences.

The problem is that when I insert a row, from a dump, that has all the values present(including the id), the sequence isn't incremented, so then when I try to insert a row, without stating the id, it trys to use the first of the sequence which is the same as a value already in the db, which results in an error, in havig two values for the same primary key.

Is there any way for me to set a default of the highest number already in the database + 1?

While I'm here, and this isn't strictly part of the above question, but I'd like to know if this will be a problem with other DB systems, such as Oracle, Access, SQL Server, etc

I think this is a fairly simple question. If that proves not to be the case I'll up the point value.
ASKER CERTIFIED SOLUTION
Avatar of tncbbthositg
tncbbthositg

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aolXFT
aolXFT

ASKER

I think that Serial is just what I need.

What exactly are serial, serial4 and serial8.

I'll on a very slow internet connection at the minute,

I'll check them out, and get back in about half an hour.
Avatar of aolXFT

ASKER

I really think from looking at the docs that serial is what I need, although I haven't had a chance to test it.

I'll post back here if it's not.

If it's not, then what I do need will surely be very similar, so I'll give you your points now.