Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function exists #14

Open
stevemmarshall opened this issue Jun 8, 2016 · 1 comment
Open

function exists #14

stevemmarshall opened this issue Jun 8, 2016 · 1 comment

Comments

@stevemmarshall
Copy link

Hi

This a nice package that I stumbled upon....

I want to check if a function exists and here's my code.. i thought it might be a namespace issue but also tried to_char and it failed... so maybe I'm doing something dumb..

CREATE OR REPLACE FUNCTION unit_tests.reformat_date_exists()
RETURNS test_result
AS
$$
DECLARE message test_result;
BEGIN
IF 1 = 1 THEN
SELECT assert.function_exists('reformat_date') INTO message;
RETURN message;
END IF;

SELECT assert.ok('End of test.') INTO message;  
RETURN message; 

END
$$
LANGUAGE plpgsql;

@orlando-colamatteo
Copy link

orlando-colamatteo commented Aug 6, 2022

You can use the built-in function assert.function_exists:

--use this to determine the signature of your function

SELECT replace(nspname || '.' || proname || '(' || oidvectortypes(proargtypes) || ')', ' ' , '')::text as function_signature
FROM pg_catalog.pg_namespace n
    JOIN    pg_catalog.pg_proc p ON      pronamespace = n.oid
WHERE nspname = 'assert' and  proname = 'function_exists'; -- test values <-- replace with your schema and function name
--then feed the function_signature into assert.function_exists

SELECT * FROM assert.function_exists('<function_signature>')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants