strange error when inserting via a SRF into a table with a foreign key constraint

From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: "PgSQL General" <pgsql-general(at)postgresql(dot)org>
Subject: strange error when inserting via a SRF into a table with a foreign key constraint
Date: 2006-10-11 21:18:13
Message-ID: b42b73150610111418r1e947a2i7778e06463a42440@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

I got the error mesage,

ERROR: could not find relation 19693 among query result relations,

from a strange interaction between inser, foreign keys and a udf.
After a but of trial and error, I came up with a test case:

create or replace function explode_array(in_array anyarray) returns
setof anyelement as
$$
select ($1)[s] from generate_series(1,array_upper($1, 1)) as s;
$$
language sql immutable;

create table fp1(a text, b text, primary key(a,b));
create table foo (a text, b numeric, c text);

insert into foo select 'a', 1, explode_array(string_to_array('a,b',
',')); -- works
truncate foo;

alter table foo add foreign key(a,b) references fp1(a,b) on delete cascade;

insert into foo select 'a', 1, explode_array(string_to_array('a,b',
',')); -- fails

I confirmed this on 8.1.4.

merlin

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Karsten Hilbert 2006-10-11 21:21:58 Re: Is it possible to return custom type as proper ROW?
Previous Message Richard Broersma Jr 2006-10-11 21:10:38 Re: question on renaming a foreign key

Browse pgsql-hackers by date

  From Date Subject
Next Message Richard Broersma Jr 2006-10-11 21:43:39 Re: strange error when inserting via a SRF into a table with a foreign key constraint
Previous Message Jim C. Nasby 2006-10-11 21:05:47 Re: hstore isexists