Re: [GENERAL] serial data type usage

2008-11-06 Thread Berend Tober
EXT-Rothermel, Peter M wrote: I have a table where I would like the primary key to be generated during the insert. Here is a simplified example: CREATE TABLE employee_type { tname varchar(10) PRIMARY KEY, id_prefix char(1) ; ... } tname | id_prefix --+--

Re: [GENERAL] serial data type usage

2008-11-06 Thread Alan Hodgson
On Thursday 06 November 2008, "EXT-Rothermel, Peter M" <[EMAIL PROTECTED]> wrote: > I have thought about using the serial data type for the employee.id but > I also want to automate the prepending of the { W, M, E } prefix. > You'll need write a before-insert trigger to assign the ID. -- Alan

Re: [GENERAL] Serial Data Type

2008-04-02 Thread Tom Lane
"Adam Rich" <[EMAIL PROTECTED]> writes: >> I have just created a table using SELECT INTO however the PK was >> supposed to be a serial. It is now an integer. To make it a serial I >> just create the seq and set the default to be the nextval() of that >> sequence right? is there anything else I need

Re: [GENERAL] Serial Data Type

2008-04-02 Thread Merlin Moncure
On Wed, Apr 2, 2008 at 10:12 PM, Naz Gassiep <[EMAIL PROTECTED]> wrote: > I have just created a table using SELECT INTO however the PK was > supposed to be a serial. It is now an integer. To make it a serial I > just create the seq and set the default to be the nextval() of that > sequence right

Re: [GENERAL] Serial Data Type

2008-04-02 Thread Adam Rich
> I have just created a table using SELECT INTO however the PK was > supposed to be a serial. It is now an integer. To make it a serial I > just create the seq and set the default to be the nextval() of that > sequence right? is there anything else I need to do? You'll want to do this: ALTER SE

Re: [GENERAL] serial data type

2004-09-25 Thread Doug McNaught
Joseph Healy <[EMAIL PROTECTED]> 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 d

Re: [GENERAL] serial data type

2004-09-25 Thread Joseph Healy
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 -

Re: [GENERAL] serial data type

2004-09-25 Thread Doug McNaught
Tom Allison <[EMAIL PROTECTED]> 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. > > An

Re: [GENERAL] serial data type

2004-09-25 Thread Tom Allison
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 ?

Re: [GENERAL] serial data type

2004-09-25 Thread Doug McNaught
Tom Allison <[EMAIL PROTECTED]> 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 trigger