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

ERROR: syntax error at or near "CASCADE" for "DROP FUNCTION" #31

Open
David-Angel opened this issue Apr 26, 2018 · 1 comment
Open

ERROR: syntax error at or near "CASCADE" for "DROP FUNCTION" #31

David-Angel opened this issue Apr 26, 2018 · 1 comment

Comments

@David-Angel
Copy link

We are getting this error on the generated drop function statements:

ERROR: syntax error at or near "CASCADE"

FOR REAL EXAMPLE:
STATEMENT: DROP FUNCTION default_data.complex_schema_changes_version CASCADE;

It should be written "drop function default_data.complex_schema_changes_version() cascade;
(missing empty parenthesis)

Here is a working example of dropping functions using the "pg_get_function_identity_arguments".
You should be able to easily fix it using this.

with
functions (simple_name, full_name, arguments) as
(
select
(case when ((ns.nspname is null) or (ns.nspname = '')) then '' else ns.nspname || '.' end) || p.proname,
(case when ((ns.nspname is null) or (ns.nspname = '')) then '' else '"' || ns.nspname || '".' end) || '"' || p.proname || '"',
pg_get_function_identity_arguments(p.oid)
from
pg_proc p
left join pg_namespace ns on ns.oid = p.pronamespace
where
-- Exclude system schemas
lower(ns.nspname) not in ('pg_catalog' , 'information_schema')
order by
ns.nspname, p.proname
)
select
simple_name,
format('DROP FUNCTION %s(%s);', f.full_name, f.arguments)
from
functions f

@joncrlsn
Copy link
Owner

Thank you, David. I'll try to make time to work on it this weekend.

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