function_returns() cannot find functions
jonjonw opened this issue · 1 comments
jonjonw commented
function_returns()
cannot seem to detect functions that has_function()
can detect.
For example,
BEGIN;
SELECT plan(2);
CREATE FUNCTION _test(val int)
RETURNS VOID
LANGUAGE SQL AS $$
SELECT 1;
$$;
SELECT has_function('_test', '{int}'::text[]);
SELECT function_returns('_test', '{int}'::text[], 'void');
SELECT * FROM finish();
ROLLBACK;
results in:
pg_prove -r bug.pg
bug.pg .. 1/2
# Failed test 2: "Function _test(int) should return void"
# Function _test(int) does not exist
# Looks like you failed 1 test of 2
bug.pg .. Failed 1/2 subtests
Test Summary Report
-------------------
bug.pg (Wstat: 0 Tests: 2 Failed: 1)
Failed test: 2
Files=1, Tests=2, 0 wallclock secs ( 0.02 usr + 0.00 sys = 0.02 CPU)
Result: FAIL
theory commented
This is due to a limitation of the text formatting of argument data types; from the documentation for function_returns()
:
Tests that a particular function returns a particular data type. The
:args[]
and:type
arguments should be formatted as they would be displayed in the
view of a function using the\df
command inpsql
. For example, use
"character varying" rather than "varchar", and "boolean" rather than "bool".
In your case, that means you have to use integer
instead of int
. Here's how it looks in psql
:
david=# CREATE FUNCTION _test(val int) RETURNS VOID LANGUAGE SQL AS 'SELECT 1';
CREATE FUNCTION
Time: 7.428 ms
david=# \df _test
List of functions
Schema | Name | Result data type | Argument data types | Type
--------+-------+------------------+---------------------+------
public | _test | void | val integer | func