pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nuchanard Chiannilkulchai <nuch@valigene.com>
To: pgsql-sql@hub.org
Subject: automatic incrementation
Date: Wed, 09 Jun 1999 10:47:25 +0200
Message-ID: <375E2A1D.FC614366@valigene.com> (raw)

hello,

I have a table with the field 'id' which i would like to increment at
each insert automatically.
The idea is to create a function which determines the max(id) and then a
rule to insert instead
the real insertion instruction, with the next id value.

-- table
create table toto (
        id      int4       primary key,
        project char(8) not null,
        comments text
);
insert into toto values (1,'PTest','ndfjSHJG');
insert into toto values (2,'PTest','ndfjSHJG');
insert into toto values (3,'PTest','ndfjSHJG');

-- function
create function nextid(toto) returns int4
        as ' select max($1.id)+1 as id ; '
        language 'sql';

**** ERROR:  type id lookup of 12 failed
This is my first problem

-- rule
create rule r_id  as on insert to toto
        do instead
        insert into toto (id, project, comments) values (nextid(),
new.project, new.comments);

**** The next problem may be the rule writing !!!
I would like to have , even some other suggestions to make it works.
I can't use a sequence table because I've already one in the database.

Thanks,
    Nuch




view thread (3+ messages)  latest in thread

Message-ID: <375E2A1D.FC614366@valigene.com>
Permalink:  ../375E2A1D.FC614366@valigene.com/
Also on:    postgresql.org/message-id/375E2A1D.FC614366@valigene.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: nuch@valigene.com, pgsql-sql@hub.org
  Subject: Re: automatic incrementation
  In-Reply-To: <375E2A1D.FC614366@valigene.com>
  References: <375E2A1D.FC614366@valigene.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox