To clarify the issue I am having, I am writing pgtap unit tests on DB and one of my functions returns a table. However, the pgtap function function_returns
does not have a definition for table check and their columns (names and data types).
These are all the overloads of the function:
SELECT function_returns( :schema, :function, :args, :type, :description );
SELECT function_returns( :schema, :function, :args, :type );
SELECT function_returns( :schema, :function, :type, :description );
SELECT function_returns( :schema, :function, :type );
SELECT function_returns( :function, :args, :type, :description );
SELECT function_returns( :function, :args, :type );
SELECT function_returns( :function, :type, :description );
SELECT function_returns( :function, :type );
You may read the full definition and what each parameter stands for in the official documentation
Basically the issue is that :type
does not work for table
.
So I am wondering where these user defined functions are saved in Postgres (trying to write my own version and hopefully contribute to the pgtap project).
After digging in the source code I found the function used in the background to check for this, it's called _func_compare
CREATE OR REPLACE FUNCTION _func_compare( NAME, NAME, NAME[], anyelement, anyelement, TEXT)
RETURNS TEXT AS $$
SELECT CASE WHEN $4 IS NULL
THEN ok( FALSE, $6 ) || _nosuch($1, $2, $3)
ELSE is( $4, $5, $6 )
END;
$$ LANGUAGE SQL;
And I can't find out how the author was checking for valid return definition of the function.
returns table
=record
in pg_type. But from what I see there's no way to see complete return (all columns, their type and name in return). I see I can find this info about input arguments (proargnames
,proargtypes
) but not output?proargnames
also includes bothin
andout
defined parameters so it's not ideal. I am hoping I didn't miss anything like last time :(