pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedProblem with stored procedure
3+ messages / 3 participants
[nested] [flat]
* Problem with stored procedure
@ 2004-08-26 13:07 Patrice OLIVER <oliverp21@free.fr>
2004-08-26 13:31 ` Re: Problem with stored procedure Richard Huxton <dev@archonet.com>
2004-08-26 14:59 ` Re: Problem with stored procedure Antonis Antoniou <a.antoniou@albourne.com>
0 siblings, 2 replies; 3+ messages in thread
From: Patrice OLIVER @ 2004-08-26 13:07 UTC (permalink / raw)
To: pgsql-sql
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
Attachments:
oliverp21.vcf (text/x-vcard, 122B) download
begin:vcard
fn:Patrice OLIVER
n:OLIVER;Patrice
email;internet:oliverp21@free.fr
x-mozilla-html:FALSE
version:2.1
end:vcard
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Problem with stored procedure
2004-08-26 13:07 Problem with stored procedure Patrice OLIVER <oliverp21@free.fr>
@ 2004-08-26 13:31 ` Richard Huxton <dev@archonet.com>
1 sibling, 0 replies; 3+ messages in thread
From: Richard Huxton @ 2004-08-26 13:31 UTC (permalink / raw)
To: Patrice OLIVER <oliverp21@free.fr>; +Cc: pgsql-sql
Patrice OLIVER wrote:
[snip]
> 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.
Before your "insert into" add:
RAISE NOTICE ''cletype = %'', cletype;
This will show what value cletype has. Presumably it's 43 and you don't
have an equivalent row in "types".
Or have I misunderstood the problem?
--
Richard Huxton
Archonet Ltd
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Problem with stored procedure
2004-08-26 13:07 Problem with stored procedure Patrice OLIVER <oliverp21@free.fr>
@ 2004-08-26 14:59 ` Antonis Antoniou <a.antoniou@albourne.com>
1 sibling, 0 replies; 3+ messages in thread
From: Antonis Antoniou @ 2004-08-26 14:59 UTC (permalink / raw)
To: Patrice OLIVER <oliverp21@free.fr>; +Cc: pgsql-sql
Patrice OLIVER wrote:
> 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'';
why not -> select *typenum* into coderet from types
where typcode = codetype and catcode = ''UV'';
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2004-08-26 14:59 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-08-26 13:07 Problem with stored procedure Patrice OLIVER <oliverp21@free.fr>
2004-08-26 13:31 ` Richard Huxton <dev@archonet.com>
2004-08-26 14:59 ` Antonis Antoniou <a.antoniou@albourne.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox