Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 386BA9FBAC8 for ; Tue, 6 Mar 2007 13:15:46 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 83138-08 for ; Tue, 6 Mar 2007 13:15:37 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id 16BAB9FB98B for ; Tue, 6 Mar 2007 13:15:38 -0400 (AST) Received: from server3.office.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id A3FBD7577E; Tue, 6 Mar 2007 17:13:29 +0000 (GMT) Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id 8154927403D; Tue, 6 Mar 2007 17:13:29 +0000 (GMT) Message-ID: <45EDA139.6070103@archonet.com> Date: Tue, 06 Mar 2007 17:13:29 +0000 From: Richard Huxton User-Agent: IceDove 1.5.0.9 (X11/20061220) MIME-Version: 1.0 To: Ezequias Rodrigues da Rocha Cc: PostgreSQL Subject: Re: Inc References: <55c095e90703060855o228c0d0bm4b021826e3899ba5@mail.gmail.com> In-Reply-To: <55c095e90703060855o228c0d0bm4b021826e3899ba5@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.21 tagged_above=0 required=5 tests=AWL, BAYES_50, FORGED_RCVD_HELO, UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200703/51 X-Sequence-Number: 27689 Ezequias Rodrigues da Rocha wrote: > Hi list, > > There is any function to increment with 1 some field. > > For example. I have a table with a field that on each update it > incrementes a field that is allways configured to 0 before the > starting of updates. Something like: CREATE FUNCTION my_autoinc() RETURNS TRIGGER AS $$ BEGIN NEW.counter := NEW.counter + 1; RETURN NEW; END; $$ LANGUAGE plpgsql; CREATE TRIGGER my_counter_trig BEFORE UPDATE ON my_table FOR EACH ROW EXECUTE PROCEDURE my_autoinc(); -- Richard Huxton Archonet Ltd