hey all. i usualy use mysql, this time i need to develop a website using postgres.
Usually i set the key to autoincrement in mysql. It appears that postgres doesnt have such a thing.
How do u deal with inserts? do you query the db to get the highest key value and then increment it with php?
what other method can i use?
thx.
i need an advice on postgres keys
Moderator: General Moderators
mmm... i see.. its a tricky approach i think. Mysql way is more simplifyed IMO.
I set the keys to serial and it will create an autosequence then i cn use next() corrent() and prev().
It took me quite some time searching and readind docs about this... postgres is not so well documented as mysql at all.
I set the keys to serial and it will create an autosequence then i cn use next() corrent() and prev().
It took me quite some time searching and readind docs about this... postgres is not so well documented as mysql at all.
This was interesting: http://www.faqts.com/knowledge_base/vie ... 204/fid/16
I've done it before but this looks familiar. I don't use nextval() or anything on my queries. I believe it actually auto-increments without needing to send it a custom function.
I've done it before but this looks familiar. I don't use nextval() or anything on my queries. I believe it actually auto-increments without needing to send it a custom function.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Anyway, i meant SERIAL 
Code: Select all
CREATE TABLE joined (
joined_id SERIAL,
firstname CHAR(20) NOT NULL,
lastname CHAR(30) NOT NULL,
PRIMARY KEY(joined_id)
)
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
I did wondertimvw wrote:Anyway, i meant SERIAL
Code: Select all
CREATE TABLE joined ( joined_id SERIAL, firstname CHAR(20) NOT NULL, lastname CHAR(30) NOT NULL, PRIMARY KEY(joined_id) )