Re: sorry, now with subject... trigger & nextval(seq)

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: sorry, now with subject... trigger & nextval(seq)
Date: 2010-05-21 01:46:52
Message-ID: 201005201846.53125.adrian.klaver@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thursday 20 May 2010 5:53:51 pm tlange(at)gwdg(dot)de wrote:
> Hello all,
>
> I'm new to triggers in PostgreSQL. I have to create a trigger on insert to
> increment a sequence to overcome MS-Access' limitation in acknowledging
> serial "datatype".
>
> Could anyone put me on right track? I was looking the whole day for
> references on that... Years ago I quickly found a reference how to do it
> in Oracle. However, I could not find anything that explained how to do
> this in postgresql... I think, it should go the direction see below... But
> how exactly :-/ ?
>
>
> Many thanks for any help, Torsten
>
>
> create table testtab (
> pid bigint,
> sometext text
> );
>
> create sequence test;
>
> -- hmm something like this...?
> CREATE FUNCTION count_up (varchar) RETURNS opaque AS '
> DECLARE
> pid_num bigint;
> BEGIN
> select into pid_num from select nextval($);
> RETURN pid_num;
> END;
> ' LANGUAGE 'plpgsql';
>
> -- and how will the trigger looks like
> ???

You know serial is just a shortcut for:

pid int NOT NULL DEFAULT nextval('seq')

I think you will find Access will place nice if you use the long form to define
your autoincrement.

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Broersma 2010-05-21 01:56:39 Re:
Previous Message tlange 2010-05-21 00:53:51 sorry, now with subject... trigger & nextval(seq)