Skip to content

Commit

Permalink
fixed parser ambiguity for nameless args
Browse files Browse the repository at this point in the history
Postgres' SQL is ambiguous in that it treats VARYING as non-reserved
this leads to ambiguity in 'CREATE FUNCTION f(character varying)'
which can be recognized as nameless argument of type 'character varying'
or argument 'character' of type 'varying'

the implemented workaround is the one that Postgres uses
it forbids technically correct 'character schema_name.varying' argument declaration but allows for the original issue to be resolved
  • Loading branch information
Endeavourl committed Jul 19, 2018
1 parent badf9cf commit f0f50ae
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions apgdiff/antlr-src/SQLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ character_string
;

function_arguments
:arg_mode=argmode? argname=identifier? argtype_data=data_type function_def_value?
:arg_mode=argmode? argname=identifier_nontype? argtype_data=data_type function_def_value?
;

function_def_value
Expand Down Expand Up @@ -1766,7 +1766,7 @@ function_call
;

function_name
: data_type
: schema_qualified_name_nontype
// allow for all built-in function except those with explicit syntax rules defined
| (identifier DOT)? tokens_simple_functions
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public void createTrigger(Create_trigger_statementContext ctx) {
ParserAbstract.getFullCtxText(ctx.getParent()));

Schema_qualified_name_nontypeContext funcNameCtx = ctx.func_name.function_name()
.data_type().predefined_type().schema_qualified_name_nontype();
.schema_qualified_name_nontype();
IdentifierContext sch = funcNameCtx.schema;
String funcSchema = sch != null ? sch.getText() : getDefSchemaName();
String funcName = funcNameCtx.identifier_nontype().getText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,11 @@ public Pair<String, String> function(Function_callContext function) {

String schemaName = null;
String functionName;
Data_typeContext dataTypeCtx = funcNameCtx.data_type();
Schema_qualified_name_nontypeContext funcNameQualCtx;
Schema_qualified_name_nontypeContext funcNameQualCtx = funcNameCtx.schema_qualified_name_nontype();

IdentifierContext id;
Tokens_simple_functionsContext tokensSimpleFunc;
if (dataTypeCtx != null &&
(funcNameQualCtx = dataTypeCtx.predefined_type().schema_qualified_name_nontype()) != null) {
if (funcNameQualCtx != null) {
functionName = funcNameQualCtx.identifier_nontype().getText();

if ((id = funcNameQualCtx.identifier()) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public PgStatement getObject() {
}

Schema_qualified_name_nontypeContext funcNameCtx = ctx.func_name.function_name()
.data_type().predefined_type().schema_qualified_name_nontype();
.schema_qualified_name_nontype();
IdentifierContext sch = funcNameCtx.schema;
String schName = sch != null ? sch.getText() : getDefSchemaName();
String objName = funcNameCtx.identifier_nontype().getText();
Expand Down

0 comments on commit f0f50ae

Please sign in to comment.