Re: Inc

From: Richard Huxton <dev(at)archonet(dot)com>
To: Ezequias Rodrigues da Rocha <ezequias(dot)rocha(at)gmail(dot)com>
Cc: PostgreSQL <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Inc
Date: 2007-03-06 17:13:29
Message-ID: 45EDA139.6070103@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

  • Inc at 2007-03-06 16:55:35 from Ezequias Rodrigues da Rocha

Responses

  • Re: Inc at 2007-03-06 17:29:03 from Ezequias Rodrigues da Rocha

Browse pgsql-sql by date

  From Date Subject
Next Message Ezequias Rodrigues da Rocha 2007-03-06 17:29:03 Re: Inc
Previous Message Ezequias Rodrigues da Rocha 2007-03-06 16:55:35 Inc