Thread: serial data type

serial data type

From
Tom Allison
Date:
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?

Re: serial data type

From
Doug McNaught
Date:
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

Re: serial data type

From
Tom Allison
Date:

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: serial data type

From
Doug McNaught
Date:
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

Re: serial data type

From
Joseph Healy
Date:
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: serial data type

From
Doug McNaught
Date:
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

Re: serial data type

From
Tom Allison
Date:

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....