@@ -28,7 +28,7 @@ create or replace function retc(int) returns two_int8s language plpgsql as
2828$$ begin return row($1,1); end $$;
2929select retc(42);
3030ERROR: returned record type does not match expected record type
31- DETAIL: Returned type integer does not match expected type bigint in column 1 .
31+ DETAIL: Returned type integer does not match expected type bigint in column "q1" (position 1) .
3232CONTEXT: PL/pgSQL function retc(integer) while casting return value to function's return type
3333-- nor extra columns
3434create or replace function retc(int) returns two_int8s language plpgsql as
@@ -50,7 +50,7 @@ create or replace function retc(int) returns two_int8s language plpgsql as
5050$$ declare r record; begin r := row($1,1); return r; end $$;
5151select retc(42);
5252ERROR: returned record type does not match expected record type
53- DETAIL: Returned type integer does not match expected type bigint in column 1 .
53+ DETAIL: Returned type integer does not match expected type bigint in column "q1" (position 1) .
5454CONTEXT: PL/pgSQL function retc(integer) while casting return value to function's return type
5555create or replace function retc(int) returns two_int8s language plpgsql as
5656$$ declare r record; begin r := row($1::int8, 1::int8, 42); return r; end $$;
@@ -386,7 +386,7 @@ DETAIL: Number of returned columns (2) does not match expected column count (3)
386386CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
387387select * from returnsrecord(42) as r(x int, y bigint); -- fail
388388ERROR: returned record type does not match expected record type
389- DETAIL: Returned type integer does not match expected type bigint in column 2 .
389+ DETAIL: Returned type integer does not match expected type bigint in column "y" (position 2) .
390390CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
391391-- same with an intermediate record variable
392392create or replace function returnsrecord(int) returns record language plpgsql as
@@ -409,7 +409,7 @@ DETAIL: Number of returned columns (2) does not match expected column count (3)
409409CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
410410select * from returnsrecord(42) as r(x int, y bigint); -- fail
411411ERROR: returned record type does not match expected record type
412- DETAIL: Returned type integer does not match expected type bigint in column 2 .
412+ DETAIL: Returned type integer does not match expected type bigint in column "y" (position 2) .
413413CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
414414-- should work the same with a missing column in the actual result value
415415create table has_hole(f1 int, f2 int, f3 int);
@@ -434,7 +434,7 @@ DETAIL: Number of returned columns (2) does not match expected column count (3)
434434CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
435435select * from returnsrecord(42) as r(x int, y bigint); -- fail
436436ERROR: returned record type does not match expected record type
437- DETAIL: Returned type integer does not match expected type bigint in column 2 .
437+ DETAIL: Returned type integer does not match expected type bigint in column "y" (position 2) .
438438CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
439439-- same with an intermediate record variable
440440create or replace function returnsrecord(int) returns record language plpgsql as
@@ -457,7 +457,7 @@ DETAIL: Number of returned columns (2) does not match expected column count (3)
457457CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
458458select * from returnsrecord(42) as r(x int, y bigint); -- fail
459459ERROR: returned record type does not match expected record type
460- DETAIL: Returned type integer does not match expected type bigint in column 2 .
460+ DETAIL: Returned type integer does not match expected type bigint in column "y" (position 2) .
461461CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
462462-- check access to a field of an argument declared "record"
463463create function getf1(x record) returns int language plpgsql as
@@ -545,6 +545,7 @@ begin
545545 return next h;
546546 return next row(5,6);
547547 return next row(7,8)::has_hole;
548+ return query select 9, 10;
548549end$$;
549550select returnssetofholes();
550551 returnssetofholes
@@ -554,7 +555,8 @@ select returnssetofholes();
554555 (3,4)
555556 (5,6)
556557 (7,8)
557- (5 rows)
558+ (9,10)
559+ (6 rows)
558560
559561create or replace function returnssetofholes() returns setof has_hole language plpgsql as
560562$$
@@ -575,6 +577,16 @@ select returnssetofholes();
575577ERROR: returned record type does not match expected record type
576578DETAIL: Number of returned columns (3) does not match expected column count (2).
577579CONTEXT: PL/pgSQL function returnssetofholes() line 3 at RETURN NEXT
580+ create or replace function returnssetofholes() returns setof has_hole language plpgsql as
581+ $$
582+ begin
583+ return query select 1, 2.0; -- fails
584+ end$$;
585+ select returnssetofholes();
586+ ERROR: structure of query does not match function result type
587+ DETAIL: Returned type numeric does not match expected type integer in column "f3" (position 2).
588+ CONTEXT: SQL statement "select 1, 2.0"
589+ PL/pgSQL function returnssetofholes() line 3 at RETURN QUERY
578590-- check behavior with changes of a named rowtype
579591create table mutable(f1 int, f2 text);
580592create function sillyaddone(int) returns int language plpgsql as
0 commit comments