X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 70CE55E46DC for ; Thu, 26 Aug 2004 10:07:09 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 41362-06 for ; Thu, 26 Aug 2004 13:07:09 +0000 (GMT) Received: from postfix3-1.free.fr (postfix3-1.free.fr [213.228.0.44]) by svr1.postgresql.org (Postfix) with ESMTP id 019E25E46F4 for ; Thu, 26 Aug 2004 10:07:07 -0300 (ADT) Received: from [192.168.0.15] (lns-th2-11-82-64-164-115.adsl.proxad.net [82.64.164.115]) by postfix3-1.free.fr (Postfix) with ESMTP id B43A41739BA for ; Thu, 26 Aug 2004 15:07:10 +0200 (CEST) Message-ID: <412DE07D.1060800@free.fr> Date: Thu, 26 Aug 2004 15:07:09 +0200 From: Patrice OLIVER User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Problem with stored procedure Content-Type: multipart/mixed; boundary="------------020000040409060302000000" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.9 tagged_above=0.0 required=5.0 tests=FROM_ENDS_IN_NUMS, MAILTO_TO_SPAM_ADDR X-Spam-Level: * X-Archive-Number: 200408/288 X-Sequence-Number: 18785 This is a multi-part message in MIME format. --------------020000040409060302000000 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hello, In this example, I use 2 tables : create table types ( typnum integer primary key, catcode varchar(2), typlib varchar(35)); create table uv ( uvnum varchar(5) primary key, typnum integer, uvlib varchar(50)); alter table uv add constraint fk_uv_type foreign key (typnum) references types (typnum) on delete restrict on update restrict; I also use stored procedures : create function numtype(varchar) returns integer as ' declare codetype alias for $1; coderet integer; begin select into coderet typnum from types where typcode = codetype and catcode = ''UV''; return coderet; end; ' language 'plpgsql'; create function insert_uv(varchar,varchar,varchar) returns integer as ' declare codeuv alias for $1; codetype alias for $2; libuv alias for $3; cletype integer; begin select into cletype numtype(codeuv); insert into uv values (codeuv, cletype, libuv); return cletype; end; ' language 'plpgsql'; When I do : select insert_uv('SGBD','DUVC','TEST BD'); I get the following message : ERROR: insert or update on table "uv" violates foreign key constraint "fk_uv_caracteri_type" DETAIL: Key (typnum)=(43) is not present in table "types". I don't kown why. Anyone has an idea ? With best regards, Patrice --------------020000040409060302000000 Content-Type: text/x-vcard; charset=utf-8; name="oliverp21.vcf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="oliverp21.vcf" begin:vcard fn:Patrice OLIVER n:OLIVER;Patrice email;internet:oliverp21@free.fr x-mozilla-html:FALSE version:2.1 end:vcard --------------020000040409060302000000--