Re: [SQL] nextval
От | Patrice Hédé |
---|---|
Тема | Re: [SQL] nextval |
Дата | |
Msg-id | Pine.LNX.3.96.980528114405.29416A-100000@paris.ivo.fr обсуждение исходный текст |
Ответ на | Re: [SQL] nextval (Jerome ALET <alet@unice.fr>) |
Список | 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 по дате отправления: