8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d45f157 commit 486cfb3Copy full SHA for 486cfb3
src/backend/executor/nodeTableFuncscan.c
@@ -364,8 +364,9 @@ tfuncInitialize(TableFuncScanState *tstate, ExprContext *econtext, Datum doc)
364
forboth(lc1, tstate->ns_uris, lc2, tstate->ns_names)
365
{
366
ExprState *expr = (ExprState *) lfirst(lc1);
367
- char *ns_name = strVal(lfirst(lc2));
+ Value *ns_node = (Value *) lfirst(lc2);
368
char *ns_uri;
369
+ char *ns_name;
370
371
value = ExecEvalExpr((ExprState *) expr, econtext, &isnull);
372
if (isnull)
@@ -374,6 +375,9 @@ tfuncInitialize(TableFuncScanState *tstate, ExprContext *econtext, Datum doc)
374
375
errmsg("namespace URI must not be null")));
376
ns_uri = TextDatumGetCString(value);
377
378
+ /* DEFAULT is passed down to SetNamespace as NULL */
379
+ ns_name = ns_node ? strVal(ns_node) : NULL;
380
+
381
routine->SetNamespace(tstate, ns_name, ns_uri);
382
}
383
src/backend/parser/parse_clause.c
@@ -779,7 +779,7 @@ transformRangeTableFunc(ParseState *pstate, RangeTableFunc *rtf)
779
/* undef ordinality column number */
780
tf->ordinalitycol = -1;
781
782
-
+ /* Process column specs */
783
names = palloc(sizeof(char *) * list_length(rtf->columns));
784
785
colno = 0;
@@ -900,15 +900,15 @@ transformRangeTableFunc(ParseState *pstate, RangeTableFunc *rtf)
900
901
foreach(lc2, ns_names)
902
903
- char *name = strVal(lfirst(lc2));
904
905
- if (name == NULL)
+ if (ns_node == NULL)
906
continue;
907
- if (strcmp(name, r->name) == 0)
+ if (strcmp(strVal(ns_node), r->name) == 0)
908
ereport(ERROR,
909
(errcode(ERRCODE_SYNTAX_ERROR),
910
errmsg("namespace name \"%s\" is not unique",
911
- name),
+ r->name),
912
parser_errposition(pstate, r->location)));
913
914
@@ -922,8 +922,9 @@ transformRangeTableFunc(ParseState *pstate, RangeTableFunc *rtf)
922
default_ns_seen = true;
923
924
925
- /* Note the string may be NULL */
926
- ns_names = lappend(ns_names, makeString(r->name));
+ /* We represent DEFAULT by a null pointer */
+ ns_names = lappend(ns_names,
927
+ r->name ? makeString(r->name) : NULL);
928
929
930
tf->ns_uris = ns_uris;
src/backend/utils/adt/ruleutils.c
@@ -9739,17 +9739,17 @@ get_tablefunc(TableFunc *tf, deparse_context *context, bool showimplicit)
9739
forboth(lc1, tf->ns_uris, lc2, tf->ns_names)
9740
9741
Node *expr = (Node *) lfirst(lc1);
9742
9743
9744
if (!first)
9745
appendStringInfoString(buf, ", ");
9746
else
9747
first = false;
9748
9749
- if (name != NULL)
+ if (ns_node != NULL)
9750
9751
get_rule_expr(expr, context, showimplicit);
9752
- appendStringInfo(buf, " AS %s", name);
+ appendStringInfo(buf, " AS %s", strVal(ns_node));
9753
9754
9755
src/include/nodes/execnodes.h
@@ -1564,8 +1564,8 @@ typedef struct TableFuncScanState
1564
ExprState *rowexpr; /* state for row-generating expression */
1565
List *colexprs; /* state for column-generating expression */
1566
List *coldefexprs; /* state for column default expressions */
1567
- List *ns_names; /* list of str nodes with namespace names */
1568
- List *ns_uris; /* list of states of namespace uri exprs */
+ List *ns_names; /* same as TableFunc.ns_names */
+ List *ns_uris; /* list of states of namespace URI exprs */
1569
Bitmapset *notnulls; /* nullability flag for each output column */
1570
void *opaque; /* table builder private space */
1571
const struct TableFuncRoutine *routine; /* table builder methods */
src/include/nodes/primnodes.h
@@ -75,12 +75,15 @@ typedef struct RangeVar
75
76
/*
77
* TableFunc - node for a table function, such as XMLTABLE.
78
+ *
79
+ * Entries in the ns_names list are either string Value nodes containing
80
+ * literal namespace names, or NULL pointers to represent DEFAULT.
81
*/
82
typedef struct TableFunc
83
84
NodeTag type;
- List *ns_uris; /* list of namespace uri */
- List *ns_names; /* list of namespace names */
85
+ List *ns_uris; /* list of namespace URI expressions */
86
+ List *ns_names; /* list of namespace names or NULL */
87
Node *docexpr; /* input document expression */
88
Node *rowexpr; /* row filter expression */
89
List *colnames; /* column names (list of String) */