Received: from maia.hub.org (maia-4.hub.org [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 74F776326EB for ; Thu, 20 May 2010 22:36:54 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 79488-06 for ; Fri, 21 May 2010 01:36:47 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from tmailer.gwdg.de (tmailer.gwdg.de [134.76.10.23]) by mail.postgresql.org (Postfix) with ESMTP id 5624D632595 for ; Thu, 20 May 2010 22:36:47 -0300 (ADT) Received: from mailer-b1.gwdg.de ([134.76.10.30] helo=mailbox.gwdg.de) by mailer.gwdg.de with esmtp (Exim 4.69) (envelope-from ) id 1OFGUp-0006TF-3m for pgsql-sql@postgresql.org; Fri, 21 May 2010 02:53:51 +0200 X-Xeceived: from 84.132.147.133 (SquirrelMail authenticated user tlange) by mailbox.gwdg.de with HTTP; Fri, 21 May 2010 02:53:51 +0200 Message-ID: <45e30277e8954d24114a9fd63720c7e7.squirrel@mailbox.gwdg.de> Date: Fri, 21 May 2010 02:53:51 +0200 Subject: sorry, now with subject... trigger & nextval(seq) From: tlange@gwdg.de To: pgsql-sql@postgresql.org User-Agent: SquirrelMail/1.4.20 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-Virus-Scanned: (clean) by exiscan+sophie X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.011 tagged_above=-5 required=5 tests=BAYES_40=-0.001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201005/94 X-Sequence-Number: 34142 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 ???