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

Add support for Create / Alter / Drop PROCEDURE #48

Merged
merged 1 commit into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions pglast/printers/ddl.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def access_priv(node, output):
enums.ObjectType.OBJECT_OPERATOR: 'OPERATOR',
enums.ObjectType.OBJECT_OPFAMILY: 'OPERATOR FAMILY',
enums.ObjectType.OBJECT_POLICY: 'POLICY',
enums.ObjectType.OBJECT_PROCEDURE: 'PROCEDURE',
enums.ObjectType.OBJECT_PUBLICATION: 'PUBLICATION',
enums.ObjectType.OBJECT_PUBLICATION_REL: 'PUBLICATION_REL',
enums.ObjectType.OBJECT_ROLE: 'ROLE',
Expand Down Expand Up @@ -157,7 +158,11 @@ def alter_default_privileges_stmt(node, output):

@node_printer('AlterFunctionStmt')
def alter_function_stmt(node, output):
output.write('ALTER FUNCTION ')
output.write('ALTER ')
if node.objtype == enums.ObjectType.OBJECT_PROCEDURE:
output.write('PROCEDURE ')
else:
output.write('FUNCTION ')
output.print_node(node.func)
output.print_list(node.actions, ' ')

Expand Down Expand Up @@ -755,7 +760,10 @@ def create_function_stmt(node, output):
output.write('CREATE ')
if node.replace:
output.write('OR REPLACE ')
output.write('FUNCTION ')
if node.is_procedure:
output.write('PROCEDURE ')
else:
output.write('FUNCTION ')
output.print_name(node.funcname)
output.write('(')

Expand Down Expand Up @@ -1308,6 +1316,7 @@ def drop_role_stmt(node, output):
def drop_stmt(node, output):
otypes = enums.ObjectType
output.write('DROP ')
# Special case functions since they are not special objects
output.writes(OBJECT_NAMES[node.removeType.value])
if node.removeType == otypes.OBJECT_INDEX:
if node.concurrent:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_printers_roundtrip/ddl/alter_function.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ ALTER FUNCTION funca(somearg text) COST 100
ALTER FUNCTION func_without_args() IMMUTABLE

ALTER FUNCTION func() SET search_path TO public,schema2

ALTER PROCEDURE func() SET schema TO public
2 changes: 2 additions & 0 deletions tests/test_printers_roundtrip/ddl/create_function.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ arglist text[]) RETURNS SETOF integer AS $$
$$ language sql

CREATE FUNCTION func() RETURNS SETOF montype AS $$ $$ language sql

CREATE PROCEDURE func() AS $$ $$ language sql
2 changes: 2 additions & 0 deletions tests/test_printers_roundtrip/ddl/drop.sql
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,5 @@ DROP USER MAPPING FOR current_user SERVER foo
DROP TYPE "Foo", bar RESTRICT

DROP VIEW x.y

DROP PROCEDURE test