auto_increment?
auto_increment?
От:
Rodrigo Bernardo Pimentel <rbp@pobox.com>
Дата:
Hi.I recently had to port a script from using Postgres to MySQL. In Postgres, when I have to use a unique id, I create a sequence
and call nextval('sequence') each time I insert a new line in the table.MySQL doesn't have sequences (as far as the documentation shows).
So I had to look for an alternative. I found an atribute "auto_increment"
which seems pretty interesting. If I do
CREATE TABLE table (
id int4 primary key auto_increment,
name text,
email text);
It automatically assigns the next value when I do
INSERT INTO table (nome, email) values ('My name', 'me@somewhere.com');
When I noticed MySQL didn't have sequences, I cursed a lot. When I
found this out, though, I kept wondering if Postgres also had it, but I
couldn't find any mention in the documentation. Does anyone know if something
similar exists? Am I doing thins the hard way? Is there any other way of
automagically getting unique ids?TIA,
rbp
________________________________________________________________________Rodrigo Bernardo Pimentel | GPG KeyID: 81F85A48LinuxSP | Fingerprint:AirGeeks |7E62 9CA2 C95B FC86 B334
_____________ Debian Linux User ______________|203E C011 2E4D 81F8 5A48
Re: [SQL] auto_increment?
От:
Oleg Broytmann <phd@phd.russ.ru>
Дата:
On Thu, 21 Oct 1999, Rodrigo Bernardo Pimentel wrote: > I recently had to port a script from using Postgres to MySQL. > In Postgres, when I have to use a unique id, I create a sequence In Postgres, you can use "serial" column type. In MySQL, it is "auto_increment". Oleg. ---- Oleg Broytmann http://members.xoom.com/phd2/ phd2@earthling.net Programmers don't die, they just GOSUB without RETURN.
Re: [SQL] auto_increment?
От:
David Rugge <davidrugge@mindspring.com>
Дата:
On Thu, 21 Oct 1999, you wrote: > When I noticed MySQL didn't have sequences, I cursed a lot. When I >found this out, though, I kept wondering if Postgres also had it, but I >couldn't find any mention in the documentation. Does anyone know if something >similar exists? Am I doing thins the hard way? Is there any other way of >automagically getting unique ids? > TIA, Use the serial datatype. It automatically creates a sequence for you that increments each time you do an insert, -- -David Rugge http://www.mindspring.com/~davidrugge/index.html