Skip site navigation (1) Skip section navigation (2)

Insert rule and seqences

From: Bo Lorentsen <bl(at)netgroup(dot)dk>
To: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Insert rule and seqences
Date: 2001-09-03 10:39:41
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
Hi ...

I would be very happy if someone could please give me a hint on this
subject, as PosgreSQL confuses me on this matter.

I have been trying to make a simple rule upon a insert statement to a
table that refers to a sequence, but I keep getting this strange error
every time i use this rule, saying :

    ERROR:  entity_seq.currval is not yet defined in this session

The idea is that I have two tables I like to bind on a insert to one of
them, like this :

    CREATE SEQUENCE entity_seq;

        id        INTEGER DEFAULT nextval( 'entity_seq' ),
        name      TEXT

        name     TEXT,
        a_ref    INTEGER NOT NULL     -- REFERENCES A( id )

    CREATE RULE insert_on_a
    TO A (
        INSERT INTO B name, a_ref VALUES( name, currval( 'entity_seq'

Is this all wrong, or is the another way to get the new 'id' value from
the A table ?

Im looking forward to be enlightened :-)



pgsql-novice by date

Next:From: Jochem van DietenDate: 2001-09-03 19:18:33
Subject: Re: Insert rule and seqences
Previous:From: Robert KleemannDate: 2001-09-03 03:28:38
Subject: how to easily reduce permissions?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group