Re: [SQL] nextval - Mailing list pgsql-sql

From Patrice Hédé
Subject Re: [SQL] nextval
Date
Msg-id Pine.LNX.3.96.980528114405.29416A-100000@paris.ivo.fr
Whole thread Raw
In response to Re: [SQL] nextval  (Jerome ALET <alet@unice.fr>)
List pgsql-sql
On Thu, 28 May 1998, Jerome ALET wrote:

> I was wrong because I had forgotten the '' but it still doesn't work
> correctly:
> First I had to remove PRIMARY KEY and NOT NULL because when I did the
> INSERT it complained about inserting a null value. This is because the
> NOT NULL check is automatically done before the RULE is executed. Is it
> a bug or a feature ? Maybe we should be able to choose the order but
> this should not exist in ANSI SQL...
> Second, look at the results of a similar RULE:
>
> CREATE TABLE auteurs (numero_auteur INT4, nom_auteur TEXT, prenom_auteur
> TEXT, email_auteur TEXT);
>
> CREATE SEQUENCE seq_auteurs INCREMENT 1 MINVALUE 1 START 1;
> CREATE

Maybe you should consider doing it with a default value as :

CREATE TABLE auteurs (numero_auteur int4 default nextval('seq_auteurs'),
                      nom_auteur    text,
                      prenom_auteur text,
                      email_auteur  text
                     );

and then, you don't need to create a rule.

then insert like this :

INSERT INTO auteurs( nom_auteur ) VALUES ( 'Jerome' );

should give you what you want, if what you really need is a unique ID.

Hope it helps :)

Patrice


--
Patrice HÉDÉ --------------------------------- patrice@idf.net -----
                     ... Looking for a job in Iceland or in Norway !
Ingénieur informaticien   -   Computer engineer   -   Tölvufræðingur
----- http://www.idf.net/patrice/ ----------------------------------


pgsql-sql by date:

Previous
From: Jerome ALET
Date:
Subject: Re: [SQL] nextval
Next
From: Jerome ALET
Date:
Subject: Re: [SQL] nextval