Thread: serial data type
Can I use the serial data type in lieu of an 'auto_number' field? I asked something like this some months ago and it seems that auto_number fields were addressed through a combination of triggers and procedures to ensure that there were do duplicate KEYS generated. Is it realistic to use the serial data type as a KEY?
Tom Allison <tallison@tacocat.net> writes: > Can I use the serial data type in lieu of an 'auto_number' field? What are the exact semantics of an "auto_number" field? > I asked something like this some months ago and it seems that > auto_number fields were addressed through a combination of triggers > and procedures to ensure that there were do duplicate KEYS generated. > > Is it realistic to use the serial data type as a KEY? Lots and lots of people do. If you're just looking for a unique key column for a single table, it works fine. -Doug -- Let us cross over the river, and rest under the shade of the trees. --T. J. Jackson, 1863
Doug McNaught wrote: >>Is it realistic to use the serial data type as a KEY? > > > Lots and lots of people do. If you're just looking for a unique key > column for a single table, it works fine. > > -Doug This is essentially what I'm looking for. Any idea how to set up a timestamp=now on every insert/update ?
Tom Allison <tallison@tacocat.net> writes: > Doug McNaught wrote: >>>Is it realistic to use the serial data type as a KEY? >> Lots and lots of people do. If you're just looking for a unique key >> column for a single table, it works fine. >> -Doug > > This is essentially what I'm looking for. > > Any idea how to set up a timestamp=now on every insert/update ? Use a trigger. -Doug -- Let us cross over the river, and rest under the shade of the trees. --T. J. Jackson, 1863
On Sat, Sep 25, 2004 at 07:20:23PM -0400, Tom Allison wrote: > > Any idea how to set up a timestamp=now on every insert/update ? when you create your table, use: create table mytable ( id serial primary key, updated timestamp default(now()), mydata int4 ); Joe
Joseph Healy <joe_healy@dodo.com.au> writes: > On Sat, Sep 25, 2004 at 07:20:23PM -0400, Tom Allison wrote: >> >> Any idea how to set up a timestamp=now on every insert/update ? > > when you create your table, use: > > create table mytable ( > id serial primary key, > updated timestamp default(now()), > mydata int4 > ); That won't change the timestamp on UPDATE queries; you need a trigger for that. -Doug -- Let us cross over the river, and rest under the shade of the trees. --T. J. Jackson, 1863
Doug McNaught wrote: > Joseph Healy <joe_healy@dodo.com.au> writes: > > >>On Sat, Sep 25, 2004 at 07:20:23PM -0400, Tom Allison wrote: >> >>>Any idea how to set up a timestamp=now on every insert/update ? >> >>when you create your table, use: >> >>create table mytable ( >> id serial primary key, >> updated timestamp default(now()), >> mydata int4 >>); > > > That won't change the timestamp on UPDATE queries; you need a trigger > for that. Thanks! Understood. I'll get to that tomorrow. Right now I'm working on data types and tables....