pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedProblem with return type of function ??? (corrected)
8+ messages / 3 participants
[nested] [flat]
* Problem with return type of function ??? (corrected)
@ 2009-10-22 11:49 Denis BUCHER <dbucherml@hsolutions.ch>
2009-10-22 14:33 ` Re: Problem with return type of function ??? (corrected) Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 8+ messages in thread
From: Denis BUCHER @ 2009-10-22 11:49 UTC (permalink / raw)
To: pgsql-sql
Hello, (CORRECTED VERSION OF MY PREVIOUS EMAIL)
I have a strange problem, because it worked in a fonction for a table,
and now I created the same (?) function for another table and it doesn't
work...
The function is accepted but at runtime I get :
ERREUR: wrong record type supplied in RETURN NEXT
CONTEXTE : PL/pgSQL function "find_sn_live" line 26 at return next
Does someone maybe knows what it could be ?
This is (a part of) my function :
> CREATE OR REPLACE FUNCTION rma.find_sn_live (varchar(30)) RETURNS SETOF rma.serial_number
> AS $_$
> DECLARE
> serialnumber ALIAS FOR $1;
> row RECORD;
> BEGIN
>
> FOR row IN
> SELECT * FROM rma.serial_number WHERE sn=serialnumber
> LOOP
> RETURN NEXT row;
> END LOOP;
>
> END;
> $_$
> LANGUAGE plpgsql STRICT;
Thanks a lot for any help !
Denis
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Problem with return type of function ??? (corrected)
2009-10-22 11:49 Problem with return type of function ??? (corrected) Denis BUCHER <dbucherml@hsolutions.ch>
@ 2009-10-22 14:33 ` Tom Lane <tgl@sss.pgh.pa.us>
2009-10-22 14:38 ` Re: Problem with return type of function ??? (corrected) Denis BUCHER <dbucherml@hsolutions.ch>
2009-10-22 15:06 ` Re: Problem with return type of function ??? (corrected) Richard Huxton <dev@archonet.com>
2009-10-22 15:15 ` Re: Problem with return type of function ??? (corrected) Denis BUCHER <dbucherml@hsolutions.ch>
0 siblings, 3 replies; 8+ messages in thread
From: Tom Lane @ 2009-10-22 14:33 UTC (permalink / raw)
To: Denis BUCHER <dbucherml@hsolutions.ch>; +Cc: pgsql-sql
Denis BUCHER <dbucherml@hsolutions.ch> writes:
> I have a strange problem, because it worked in a fonction for a table,
> and now I created the same (?) function for another table and it doesn't
> work...
> The function is accepted but at runtime I get :
> ERREUR: wrong record type supplied in RETURN NEXT
> CONTEXTE : PL/pgSQL function "find_sn_live" line 26 at return next
Does that table have any dropped columns? If you don't remember
whether you ever dropped any columns, a quick look into pg_attribute
will tell you:
select attname from pg_attribute where attrelid = 'rma.serial_number'::regclass;
plpgsql isn't tremendously good with rowtypes that contain dropped
columns. I believe this particular case is fixed in CVS HEAD, but the
patch was a bit invasive and won't get back-ported to existing releases.
The workaround is to drop and recreate the table without any dropped
columns.
regards, tom lane
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Problem with return type of function ??? (corrected)
2009-10-22 11:49 Problem with return type of function ??? (corrected) Denis BUCHER <dbucherml@hsolutions.ch>
2009-10-22 14:33 ` Re: Problem with return type of function ??? (corrected) Tom Lane <tgl@sss.pgh.pa.us>
@ 2009-10-22 14:38 ` Denis BUCHER <dbucherml@hsolutions.ch>
2 siblings, 0 replies; 8+ messages in thread
From: Denis BUCHER @ 2009-10-22 14:38 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-sql
Hello Tom,
Tom Lane a écrit :
> Denis BUCHER <dbucherml@hsolutions.ch> writes:
>> I have a strange problem, because it worked in a fonction for a table,
>> and now I created the same (?) function for another table and it doesn't
>> work...
>
>> The function is accepted but at runtime I get :
>
>> ERREUR: wrong record type supplied in RETURN NEXT
>> CONTEXTE : PL/pgSQL function "find_sn_live" line 26 at return next
>
> Does that table have any dropped columns? If you don't remember
> whether you ever dropped any columns, a quick look into pg_attribute
> will tell you:
> select attname from pg_attribute where attrelid = 'rma.serial_number'::regclass;
Yes !
attname
------------------------------
tableoid
cmax
xmax
cmin
xmin
ctid
sn_id
sn
no_client
no_art_bw
sn_fc_date
........pg.dropped.6........
........pg.dropped.7........
desc_fr
sn_cm_date
no_facture
no_commande
(17 lignes)
> plpgsql isn't tremendously good with rowtypes that contain dropped
> columns. I believe this particular case is fixed in CVS HEAD, but the
> patch was a bit invasive and won't get back-ported to existing releases.
> The workaround is to drop and recreate the table without any dropped
> columns.
OH, I see...
Thanks a lot, I will try this later today when nobody uses the
application...
Denis
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Problem with return type of function ??? (corrected)
2009-10-22 11:49 Problem with return type of function ??? (corrected) Denis BUCHER <dbucherml@hsolutions.ch>
2009-10-22 14:33 ` Re: Problem with return type of function ??? (corrected) Tom Lane <tgl@sss.pgh.pa.us>
@ 2009-10-22 15:06 ` Richard Huxton <dev@archonet.com>
2009-10-22 15:47 ` Re: Problem with return type of function ??? (corrected) Tom Lane <tgl@sss.pgh.pa.us>
2 siblings, 1 reply; 8+ messages in thread
From: Richard Huxton @ 2009-10-22 15:06 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Denis BUCHER <dbucherml@hsolutions.ch>; pgsql-sql
Tom Lane wrote:
> Denis BUCHER <dbucherml@hsolutions.ch> writes:
>
> Does that table have any dropped columns? If you don't remember
> whether you ever dropped any columns, a quick look into pg_attribute
> will tell you:
> select attname from pg_attribute where attrelid = 'rma.serial_number'::regclass;
>
> plpgsql isn't tremendously good with rowtypes that contain dropped
> columns.
I thought that only applied to columns dropped after the function was
defined. Live and learn.
--
Richard Huxton
Archonet Ltd
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Problem with return type of function ??? (corrected)
2009-10-22 11:49 Problem with return type of function ??? (corrected) Denis BUCHER <dbucherml@hsolutions.ch>
2009-10-22 14:33 ` Re: Problem with return type of function ??? (corrected) Tom Lane <tgl@sss.pgh.pa.us>
2009-10-22 15:06 ` Re: Problem with return type of function ??? (corrected) Richard Huxton <dev@archonet.com>
@ 2009-10-22 15:47 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 8+ messages in thread
From: Tom Lane @ 2009-10-22 15:47 UTC (permalink / raw)
To: Richard Huxton <dev@archonet.com>; +Cc: Denis BUCHER <dbucherml@hsolutions.ch>; pgsql-sql
Richard Huxton <dev@archonet.com> writes:
> Tom Lane wrote:
>> plpgsql isn't tremendously good with rowtypes that contain dropped
>> columns.
> I thought that only applied to columns dropped after the function was
> defined. Live and learn.
There are/were some variants that go away if you recreate the function
or start a fresh session (to clear the compiled-function cache). Not
all, unfortunately.
regards, tom lane
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Problem with return type of function ??? (corrected)
2009-10-22 11:49 Problem with return type of function ??? (corrected) Denis BUCHER <dbucherml@hsolutions.ch>
2009-10-22 14:33 ` Re: Problem with return type of function ??? (corrected) Tom Lane <tgl@sss.pgh.pa.us>
@ 2009-10-22 15:15 ` Denis BUCHER <dbucherml@hsolutions.ch>
2009-10-22 15:51 ` Re: Problem with return type of function ??? (corrected) Tom Lane <tgl@sss.pgh.pa.us>
2 siblings, 1 reply; 8+ messages in thread
From: Denis BUCHER @ 2009-10-22 15:15 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-sql
Hi Tom,
Another question :
Tom Lane a écrit :
> Denis BUCHER <dbucherml@hsolutions.ch> writes:
>> I have a strange problem, because it worked in a fonction for a table,
>> and now I created the same (?) function for another table and it doesn't
>> work...
>
>> The function is accepted but at runtime I get :
>
>> ERREUR: wrong record type supplied in RETURN NEXT
>> CONTEXTE : PL/pgSQL function "find_sn_live" line 26 at return next
>
> Does that table have any dropped columns? If you don't remember
> whether you ever dropped any columns, a quick look into pg_attribute
> will tell you:
> select attname from pg_attribute where attrelid = 'rma.serial_number'::regclass;
>
> plpgsql isn't tremendously good with rowtypes that contain dropped
> columns. I believe this particular case is fixed in CVS HEAD, but the
> patch was a bit invasive and won't get back-ported to existing releases.
> The workaround is to drop and recreate the table without any dropped
> columns.
To do this it will be a little complicated because of table
dependencies... And it could bug again at the next DROP COLUMN... Is
there a way to change my function (RETURN SETOF part) to specify the
column names/types ?
Thanks a lot again
Denis
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Problem with return type of function ??? (corrected)
2009-10-22 11:49 Problem with return type of function ??? (corrected) Denis BUCHER <dbucherml@hsolutions.ch>
2009-10-22 14:33 ` Re: Problem with return type of function ??? (corrected) Tom Lane <tgl@sss.pgh.pa.us>
2009-10-22 15:15 ` Re: Problem with return type of function ??? (corrected) Denis BUCHER <dbucherml@hsolutions.ch>
@ 2009-10-22 15:51 ` Tom Lane <tgl@sss.pgh.pa.us>
2009-10-24 09:29 ` Re: Problem with return type of function ??? (corrected) Denis BUCHER <dbucherml@hsolutions.ch>
0 siblings, 1 reply; 8+ messages in thread
From: Tom Lane @ 2009-10-22 15:51 UTC (permalink / raw)
To: Denis BUCHER <dbucherml@hsolutions.ch>; +Cc: pgsql-sql
Denis BUCHER <dbucherml@hsolutions.ch> writes:
> To do this it will be a little complicated because of table
> dependencies... And it could bug again at the next DROP COLUMN... Is
> there a way to change my function (RETURN SETOF part) to specify the
> column names/types ?
No, not really. You could maybe un-drop the columns with some manual
surgery on pg_attribute, but it doesn't seem like that's going to lead
to a nice solution.
If you were really desperate you could try back-porting the patch:
http://archives.postgresql.org/pgsql-committers/2009-08/msg00068.php
but I wouldn't want to vouch for its safety, considering it hasn't
been through a beta test cycle yet.
regards, tom lane
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Problem with return type of function ??? (corrected)
2009-10-22 11:49 Problem with return type of function ??? (corrected) Denis BUCHER <dbucherml@hsolutions.ch>
2009-10-22 14:33 ` Re: Problem with return type of function ??? (corrected) Tom Lane <tgl@sss.pgh.pa.us>
2009-10-22 15:15 ` Re: Problem with return type of function ??? (corrected) Denis BUCHER <dbucherml@hsolutions.ch>
2009-10-22 15:51 ` Re: Problem with return type of function ??? (corrected) Tom Lane <tgl@sss.pgh.pa.us>
@ 2009-10-24 09:29 ` Denis BUCHER <dbucherml@hsolutions.ch>
0 siblings, 0 replies; 8+ messages in thread
From: Denis BUCHER @ 2009-10-24 09:29 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-sql
Tom Lane a écrit :
> Denis BUCHER <dbucherml@hsolutions.ch> writes:
>> To do this it will be a little complicated because of table
>> dependencies... And it could bug again at the next DROP COLUMN... Is
>> there a way to change my function (RETURN SETOF part) to specify the
>> column names/types ?
>
> No, not really. You could maybe un-drop the columns with some manual
> surgery on pg_attribute, but it doesn't seem like that's going to lead
> to a nice solution.
>
> If you were really desperate you could try back-porting the patch:
> http://archives.postgresql.org/pgsql-committers/2009-08/msg00068.php
> but I wouldn't want to vouch for its safety, considering it hasn't
> been through a beta test cycle yet.
Finally there was no real dependencies of that table, and I've found out
that the "dependency" was my function ! Using SETOF (table) makes
impossible to DROP the table. Therefore I DROP my function and was able
to follow you advice, and it worked perfectly !
Thanks a lot for your help (as well as Richard's)
Denis
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2009-10-24 09:29 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-10-22 11:49 Problem with return type of function ??? (corrected) Denis BUCHER <dbucherml@hsolutions.ch>
2009-10-22 14:33 ` Tom Lane <tgl@sss.pgh.pa.us>
2009-10-22 14:38 ` Denis BUCHER <dbucherml@hsolutions.ch>
2009-10-22 15:06 ` Richard Huxton <dev@archonet.com>
2009-10-22 15:47 ` Tom Lane <tgl@sss.pgh.pa.us>
2009-10-22 15:15 ` Denis BUCHER <dbucherml@hsolutions.ch>
2009-10-22 15:51 ` Tom Lane <tgl@sss.pgh.pa.us>
2009-10-24 09:29 ` Denis BUCHER <dbucherml@hsolutions.ch>
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