Thread: record new has no field cat

record new has no field cat

From
Fabrice Pollet
Date:
create table inventaire (
id serial primary key,
catégorie text
constraint catégorie check (catégorie='informatique' or
catégorie='bureautique' or catégorie='technique' or catégorie='contrat'),
n°_contrat text,
n°_facture text,
n°_commande text,
nie text,
n°_barre int,
n°_série text,
ref_fabriquant text,
marque text,
désignation text,
dimension text,
nb_pieds text,
nb_tiroir text,
quantité int,
service text default 'uei' check (service='uei' or service='bcm'),
lieu text,
date datetime default 'now'::text,
individu text default getpgusername(),
check (nie notnull or n°_barre notnull));

create function func_inventaire ()
returns opaque
as 'begin
if (new.dimension isnull or new.nb_pieds isnull or new.nb_tiroir isnull) and
new.catégorie !~ ''bureautique'' then raise exception ''empname cannot be NULL
value'';
end if;
new.date=''now''::text;
new.individu=getpgusername();
return new;
end;'
language 'plpgsql';

create trigger trig_inventaire before insert or update on inventaire for each
row execute procedure func_inventaire();

ERROR:  INSERT has more expressions than target columns

I get this message when I insert in table inventaire.

--
   Fabrice POLLET

  ENSTA / LEI / AMI
 32 boulevard Victor    Tél    : +33 01 45 52 54 25
75739 PARIS CEDEX 15    Fax    : +33 01 45 52 55 87
    F R A N C E


Re: record new has no field cat

From
Tom Lane
Date:
Fabrice Pollet <pollet@ensta.fr> writes:
> ERROR:  INSERT has more expressions than target columns
> I get this message when I insert in table inventaire.

What version are you running?  I don't see a problem with 7.0.2:

play=> insert into inventaire (catgorie) values ('informatique');
ERROR:  empname cannot be NULL value
play=> insert into inventaire (catgorie,dimension,nb_pieds) values ('informatique','z','3');
ERROR:  empname cannot be NULL value
play=> insert into inventaire (catgorie,dimension,nb_pieds,nb_tiroir) values ('informatique','z','3','4');
ERROR:  ExecAppend: rejected due to CHECK constraint $3
play=> insert into inventaire (catgorie,dimension,nb_pieds,nb_tiroir,nie) values ('informatique','z','3','4','q');
INSERT 335042 1
play=>

Possibly more to the point, what is your INSERT command exactly?

            regards, tom lane