Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 64C08632670 for ; Thu, 20 May 2010 22:47:04 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 75347-09 for ; Fri, 21 May 2010 01:46:56 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pv0-f174.google.com (mail-pv0-f174.google.com [74.125.83.174]) by mail.postgresql.org (Postfix) with ESMTP id 19F3963233E for ; Thu, 20 May 2010 22:46:55 -0300 (ADT) Received: by pvg3 with SMTP id 3so194588pvg.19 for ; Thu, 20 May 2010 18:46:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:reply-to:to:subject:date :user-agent:references:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:message-id; bh=4SvBCSyCH7OtYJzxVmBX3sIpnaIDaGe0LIwA1vuEEPs=; b=q9lAy4zO2Jb2cU7sPAMqGOsKkYJGIwPzkXPijR4Eza8N1M+g8sMNBhDm0pw5t+6pmm 7JP3+Df09Ua78avwobF0Jjq4Oj+CSpOP/5iFpu7BWjbnSbr9i/DSuHa104ojTaYKznII 0/VzsD5U9DpYpnj3an4I5FjN4PIt3qgK8vabY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:reply-to:to:subject:date:user-agent:references:in-reply-to :mime-version:content-type:content-transfer-encoding :content-disposition:message-id; b=CpbYiL6PLthVviii5JRo8ftCHEz9IEpE6odg0EzsGYekyT/Pg1+4BJB4dXtdOKAy4H R1jHX04ONzAW3w56FS4vrmUQtwkP1YGsaJLfDyIrqQidA2/KqDPUKwKf9hBHLonwKInq a9oUeeMCF/cWooODsbZnvphLKphiUlJFvXqM8= Received: by 10.140.55.10 with SMTP id d10mr637070rva.247.1274406413958; Thu, 20 May 2010 18:46:53 -0700 (PDT) Received: from tucker.local (c-24-17-164-54.hsd1.wa.comcast.net [24.17.164.54]) by mx.google.com with ESMTPS id h11sm435873rvm.21.2010.05.20.18.46.52 (version=SSLv3 cipher=RC4-MD5); Thu, 20 May 2010 18:46:53 -0700 (PDT) From: Adrian Klaver Reply-To: adrian.klaver@gmail.com To: pgsql-sql@postgresql.org Subject: Re: sorry, now with subject... trigger & nextval(seq) Date: Thu, 20 May 2010 18:46:52 -0700 User-Agent: KMail/1.9.10 References: <45e30277e8954d24114a9fd63720c7e7.squirrel@mailbox.gwdg.de> In-Reply-To: <45e30277e8954d24114a9fd63720c7e7.squirrel@mailbox.gwdg.de> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201005201846.53125.adrian.klaver@gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201005/95 X-Sequence-Number: 34143 On Thursday 20 May 2010 5:53:51 pm tlange@gwdg.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.klaver@gmail.com