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

chore: update libpg_query source to 680f5ee67c6fdae497c8d1edfadd02b9b8eac74f #119

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ benchmark:

# --- Below only needed for releasing new versions

LIB_PG_QUERY_TAG = 43bad3cbcd1a70a30494b64f464c3f60579884ed
LIB_PG_QUERY_TAG = 680f5ee67c6fdae497c8d1edfadd02b9b8eac74f

root_dir := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
LIB_TMPDIR = $(root_dir)/tmp
Expand Down
4 changes: 3 additions & 1 deletion parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,8 @@ var parsePlPgSQLTests = []struct {
`CREATE OR REPLACE FUNCTION cs_fmt_browser_version(v_name varchar,` +
`v_version varchar) ` +
`RETURNS varchar AS $$ ` +
`DECLARE ` +
`CURS1 CURSOR FOR SELECT 1;` +
`BEGIN ` +
` IF v_version IS NULL THEN` +
` RETURN v_name;` +
Expand All @@ -680,7 +682,7 @@ var parsePlPgSQLTests = []struct {
`END;` +
`$$ LANGUAGE plpgsql;`,
`[
{"PLpgSQL_function":{"datums":[{"PLpgSQL_var":{"refname":"v_name","datatype":{"PLpgSQL_type":{"typname":"UNKNOWN"}}}},{"PLpgSQL_var":{"refname":"v_version","datatype":{"PLpgSQL_type":{"typname":"UNKNOWN"}}}},{"PLpgSQL_var":{"refname":"found","datatype":{"PLpgSQL_type":{"typname":"UNKNOWN"}}}}],"action":{"PLpgSQL_stmt_block":{"lineno":1,"body":[{"PLpgSQL_stmt_if":{"lineno":1,"cond":{"PLpgSQL_expr":{"query":"v_version IS NULL","parseMode":2}},"then_body":[{"PLpgSQL_stmt_return":{"lineno":1,"expr":{"PLpgSQL_expr":{"query":"v_name","parseMode":2}}}}]}},{"PLpgSQL_stmt_return":{"lineno":1,"expr":{"PLpgSQL_expr":{"query":"v_name || '/' || v_version","parseMode":2}}}}]}}}}
{"PLpgSQL_function":{"datums":[{"PLpgSQL_var":{"refname":"v_name","datatype":{"PLpgSQL_type":{"typname":"pg_catalog.\"varchar\""}}}},{"PLpgSQL_var":{"refname":"v_version","datatype":{"PLpgSQL_type":{"typname":"pg_catalog.\"varchar\""}}}},{"PLpgSQL_var":{"refname":"found","datatype":{"PLpgSQL_type":{"typname":"pg_catalog.\"boolean\""}}}},{"PLpgSQL_var":{"refname":"curs1","lineno":1,"datatype":{"PLpgSQL_type":{"typname":"pg_catalog.refcursor"}},"cursor_explicit_expr":{"PLpgSQL_expr":{"query":"SELECT 1","parseMode":0}},"cursor_explicit_argrow":-1,"cursor_options":256}}],"action":{"PLpgSQL_stmt_block":{"lineno":1,"body":[{"PLpgSQL_stmt_if":{"lineno":1,"cond":{"PLpgSQL_expr":{"query":"v_version IS NULL","parseMode":2}},"then_body":[{"PLpgSQL_stmt_return":{"lineno":1,"expr":{"PLpgSQL_expr":{"query":"v_name","parseMode":2}}}}]}},{"PLpgSQL_stmt_return":{"lineno":1,"expr":{"PLpgSQL_expr":{"query":"v_name || '/' || v_version","parseMode":2}}}}]}}}}
]`,
},
}
Expand Down
4 changes: 3 additions & 1 deletion parser/pg_query_outfuncs_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ _outOidList(StringInfo out, const List *node)
static void
_outInteger(StringInfo out, const Integer *node)
{
if (node->ival > 0)
/* Don't output anything if the value is the default (0), to match
* protobuf's behavior. */
if (node->ival != 0)
appendStringInfo(out, "\"ival\":%d", node->ival);
}

Expand Down
2 changes: 1 addition & 1 deletion parser/pg_query_parse_plpgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static PLpgSQL_function *compile_create_function_stmt(CreateFunctionStmt* stmt)
PLpgSQL_variable *argvariable;
PLpgSQL_nsitem_type argitemtype;
snprintf(buf, sizeof(buf), "$%d", foreach_current_index(lc) + 1);
argdtype = plpgsql_build_datatype(UNKNOWNOID, -1, InvalidOid, NULL);
argdtype = plpgsql_build_datatype(UNKNOWNOID, -1, InvalidOid, param->argType);
argvariable = plpgsql_build_variable(param->name ? param->name : buf, 0, argdtype, false);
argitemtype = argvariable->dtype == PLPGSQL_DTYPE_VAR ? PLPGSQL_NSTYPE_VAR : PLPGSQL_NSTYPE_REC;
plpgsql_ns_additem(argitemtype, argvariable->dno, buf);
Expand Down
12 changes: 12 additions & 0 deletions parser/src_backend_utils_adt_ruleutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Symbols referenced in this file:
* - quote_identifier
* - quote_all_identifiers
* - quote_qualified_identifier
*--------------------------------------------------------------------
*/

Expand Down Expand Up @@ -1718,7 +1719,18 @@ quote_identifier(const char *ident)
* Return a name of the form qualifier.ident, or just ident if qualifier
* is NULL, quoting each component if necessary. The result is palloc'd.
*/
char *
quote_qualified_identifier(const char *qualifier,
const char *ident)
{
StringInfoData buf;

initStringInfo(&buf);
if (qualifier)
appendStringInfo(&buf, "%s.", quote_identifier(qualifier));
appendStringInfoString(&buf, quote_identifier(ident));
return buf.data;
}

/*
* get_relation_name
Expand Down
46 changes: 45 additions & 1 deletion parser/src_pl_plpgsql_src_pl_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,51 @@ plpgsql_build_recfield(PLpgSQL_rec *rec, const char *fldname)
* It can be NULL if the type could not be a composite type, or if it was
* identified by OID to begin with (e.g., it's a function argument type).
*/
PLpgSQL_type * plpgsql_build_datatype(Oid typeOid, int32 typmod, Oid collation, TypeName *origtypname) { PLpgSQL_type *typ; typ = (PLpgSQL_type *) palloc0(sizeof(PLpgSQL_type)); typ->typname = pstrdup("UNKNOWN"); typ->ttype = PLPGSQL_TTYPE_SCALAR; return typ; }

PLpgSQL_type * plpgsql_build_datatype(Oid typeOid, int32 typmod, Oid collation, TypeName *origtypname)
{
PLpgSQL_type *typ;
char *ident = NULL, *ns = NULL;
typ = (PLpgSQL_type *) palloc0(sizeof(PLpgSQL_type));

typ->ttype = PLPGSQL_TTYPE_SCALAR;
typ->atttypmod = typmod;
typ->collation = collation;

if (origtypname) {
typ->typoid = origtypname->typeOid;

if (list_length(origtypname->names) == 1) {
ident = linitial_node(String, origtypname->names)->sval;
} else if (list_length(origtypname->names) == 2) {
ns = linitial_node(String, origtypname->names)->sval;
ident = lsecond_node(String, origtypname->names)->sval;
}
} else {
typ->typoid = typeOid;
ns = "pg_catalog";
switch(typeOid)
{
case BOOLOID:
ident = "boolean";
break;
case INT4OID:
ident = "integer";
break;
case TEXTOID:
ident = "text";
break;
case REFCURSOROID:
ident = "refcursor";
break;
}
}
if (ident) {
typ->typname = quote_qualified_identifier(ns, ident);
}
return typ;
}



/*
Expand Down
2 changes: 1 addition & 1 deletion pg_query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.