@ -28,7 +28,7 @@ create or replace function retc(int) returns two_int8s language plpgsql as
$$ begin return row($1,1); end $$;
$$ begin return row($1,1); end $$;
select retc(42);
select retc(42);
ERROR: returned record type does not match expected record type
ERROR: returned record type does not match expected record type
DETAIL: Returned type integer does not match expected type bigint in column 1.
DETAIL: Returned type integer does not match expected type bigint in column "q 1" (position 1) .
CONTEXT: PL/pgSQL function retc(integer) while casting return value to function's return type
CONTEXT: PL/pgSQL function retc(integer) while casting return value to function's return type
-- nor extra columns
-- nor extra columns
create or replace function retc(int) returns two_int8s language plpgsql as
create 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
$$ declare r record; begin r := row($1,1); return r; end $$;
$$ declare r record; begin r := row($1,1); return r; end $$;
select retc(42);
select retc(42);
ERROR: returned record type does not match expected record type
ERROR: returned record type does not match expected record type
DETAIL: Returned type integer does not match expected type bigint in column 1.
DETAIL: Returned type integer does not match expected type bigint in column "q 1" (position 1) .
CONTEXT: PL/pgSQL function retc(integer) while casting return value to function's return type
CONTEXT: PL/pgSQL function retc(integer) while casting return value to function's return type
create or replace function retc(int) returns two_int8s language plpgsql as
create or replace function retc(int) returns two_int8s language plpgsql as
$$ declare r record; begin r := row($1::int8, 1::int8, 42); return r; end $$;
$$ 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)
CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
select * from returnsrecord(42) as r(x int, y bigint); -- fail
select * from returnsrecord(42) as r(x int, y bigint); -- fail
ERROR: returned record type does not match expected record type
ERROR: returned record type does not match expected record type
DETAIL: Returned type integer does not match expected type bigint in column 2.
DETAIL: Returned type integer does not match expected type bigint in column "y" (position 2) .
CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
-- same with an intermediate record variable
-- same with an intermediate record variable
create or replace function returnsrecord(int) returns record language plpgsql as
create 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)
CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
select * from returnsrecord(42) as r(x int, y bigint); -- fail
select * from returnsrecord(42) as r(x int, y bigint); -- fail
ERROR: returned record type does not match expected record type
ERROR: returned record type does not match expected record type
DETAIL: Returned type integer does not match expected type bigint in column 2.
DETAIL: Returned type integer does not match expected type bigint in column "y" (position 2) .
CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
-- should work the same with a missing column in the actual result value
-- should work the same with a missing column in the actual result value
create table has_hole(f1 int, f2 int, f3 int);
create 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)
CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
select * from returnsrecord(42) as r(x int, y bigint); -- fail
select * from returnsrecord(42) as r(x int, y bigint); -- fail
ERROR: returned record type does not match expected record type
ERROR: returned record type does not match expected record type
DETAIL: Returned type integer does not match expected type bigint in column 2.
DETAIL: Returned type integer does not match expected type bigint in column "y" (position 2) .
CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
-- same with an intermediate record variable
-- same with an intermediate record variable
create or replace function returnsrecord(int) returns record language plpgsql as
create 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)
CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
select * from returnsrecord(42) as r(x int, y bigint); -- fail
select * from returnsrecord(42) as r(x int, y bigint); -- fail
ERROR: returned record type does not match expected record type
ERROR: returned record type does not match expected record type
DETAIL: Returned type integer does not match expected type bigint in column 2.
DETAIL: Returned type integer does not match expected type bigint in column "y" (position 2) .
CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
CONTEXT: PL/pgSQL function returnsrecord(integer) while casting return value to function's return type
-- check access to a field of an argument declared "record"
-- check access to a field of an argument declared "record"
create function getf1(x record) returns int language plpgsql as
create function getf1(x record) returns int language plpgsql as
@ -545,6 +545,7 @@ begin
return next h;
return next h;
return next row(5,6);
return next row(5,6);
return next row(7,8)::has_hole;
return next row(7,8)::has_hole;
return query select 9, 10;
end$$;
end$$;
select returnssetofholes();
select returnssetofholes();
returnssetofholes
returnssetofholes
@ -554,7 +555,8 @@ select returnssetofholes();
(3,4)
(3,4)
(5,6)
(5,6)
(7,8)
(7,8)
(5 rows)
(9,10)
(6 rows)
create or replace function returnssetofholes() returns setof has_hole language plpgsql as
create or replace function returnssetofholes() returns setof has_hole language plpgsql as
$$
$$
@ -575,6 +577,16 @@ select returnssetofholes();
ERROR: returned record type does not match expected record type
ERROR: returned record type does not match expected record type
DETAIL: Number of returned columns (3) does not match expected column count (2).
DETAIL: Number of returned columns (3) does not match expected column count (2).
CONTEXT: PL/pgSQL function returnssetofholes() line 3 at RETURN NEXT
CONTEXT: PL/pgSQL function returnssetofholes() line 3 at RETURN NEXT
create or replace function returnssetofholes() returns setof has_hole language plpgsql as
$$
begin
return query select 1, 2.0; -- fails
end$$;
select returnssetofholes();
ERROR: structure of query does not match function result type
DETAIL: Returned type numeric does not match expected type integer in column "f3" (position 2).
CONTEXT: SQL statement "select 1, 2.0"
PL/pgSQL function returnssetofholes() line 3 at RETURN QUERY
-- check behavior with changes of a named rowtype
-- check behavior with changes of a named rowtype
create table mutable(f1 int, f2 text);
create table mutable(f1 int, f2 text);
create function sillyaddone(int) returns int language plpgsql as
create function sillyaddone(int) returns int language plpgsql as