*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.613 2008/04/29 14:59:16 alvherre Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.614 2008/04/29 20:44:49 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
static Node *makeStringConstCast(char *str, TypeName *typename);
static Node *makeIntConst(int val);
static Node *makeFloatConst(char *str);
+static Node *makeBitStringConst(char *str);
+static Node *makeNullAConst(void);
static Node *makeAConst(Value *v);
static Node *makeBoolAConst(bool state);
static FuncCall *makeOverlaps(List *largs, List *rargs, int location);
| ALL
{
/* LIMIT ALL is represented as a NULL constant */
- A_Const *n = makeNode(A_Const);
- n->val.type = T_Null;
- $$ = (Node *)n;
+ $$ = makeNullAConst();
}
;
| a_expr SIMILAR TO a_expr %prec SIMILAR
{
- A_Const *c = makeNode(A_Const);
FuncCall *n = makeNode(FuncCall);
- c->val.type = T_Null;
n->funcname = SystemFuncName("similar_escape");
- n->args = list_make2($4, (Node *) c);
+ n->args = list_make2($4, makeNullAConst());
n->agg_star = FALSE;
n->agg_distinct = FALSE;
n->location = @2;
}
| a_expr NOT SIMILAR TO a_expr %prec SIMILAR
{
- A_Const *c = makeNode(A_Const);
FuncCall *n = makeNode(FuncCall);
- c->val.type = T_Null;
n->funcname = SystemFuncName("similar_escape");
- n->args = list_make2($5, (Node *) c);
+ n->args = list_make2($5, makeNullAConst());
n->agg_star = FALSE;
n->agg_distinct = FALSE;
n->location = @5;
xml_root_version: VERSION_P a_expr
{ $$ = $2; }
| VERSION_P NO VALUE_P
- {
- A_Const *val = makeNode(A_Const);
- val->val.type = T_Null;
- $$ = (Node *) val;
- }
+ { $$ = makeNullAConst(); }
;
opt_xml_root_standalone: ',' STANDALONE_P YES_P
extract_list:
extract_arg FROM a_expr
{
- A_Const *n = makeNode(A_Const);
- n->val.type = T_String;
- n->val.val.str = $1;
- $$ = list_make2((Node *) n, $3);
+ $$ = list_make2(makeStringConst($1), $3);
}
| /*EMPTY*/ { $$ = NIL; }
;
* which it is likely to do if the second argument
* is unknown or doesn't have an implicit cast to int4.
*/
- A_Const *n = makeNode(A_Const);
- n->val.type = T_Integer;
- n->val.val.ival = 1;
- $$ = list_make3($1, (Node *) n,
+ $$ = list_make3($1, makeIntConst(1),
makeTypeCast($2, SystemTypeName("int4")));
}
| expr_list
*/
AexprConst: Iconst
{
- A_Const *n = makeNode(A_Const);
- n->val.type = T_Integer;
- n->val.val.ival = $1;
- $$ = (Node *)n;
+ $$ = makeIntConst($1);
}
| FCONST
{
- A_Const *n = makeNode(A_Const);
- n->val.type = T_Float;
- n->val.val.str = $1;
- $$ = (Node *)n;
+ $$ = makeFloatConst($1);
}
| Sconst
{
- A_Const *n = makeNode(A_Const);
- n->val.type = T_String;
- n->val.val.str = $1;
- $$ = (Node *)n;
+ $$ = makeStringConst($1);
}
| BCONST
{
- A_Const *n = makeNode(A_Const);
- n->val.type = T_BitString;
- n->val.val.str = $1;
- $$ = (Node *)n;
+ $$ = makeBitStringConst($1);
}
| XCONST
{
* a <general literal> shall not be a
* <bit string literal> or a <hex string literal>.
*/
- A_Const *n = makeNode(A_Const);
- n->val.type = T_BitString;
- n->val.val.str = $1;
- $$ = (Node *)n;
+ $$ = makeBitStringConst($1);
}
| func_name Sconst
{
}
| NULL_P
{
- A_Const *n = makeNode(A_Const);
- n->val.type = T_Null;
- $$ = (Node *)n;
+ $$ = makeNullAConst();
}
;
n->val.type = T_Float;
n->val.val.str = str;
- return makeTypeCast((Node *)n, SystemTypeName("float8"));
+ return (Node *)n;
+}
+
+static Node *
+makeBitStringConst(char *str)
+{
+ A_Const *n = makeNode(A_Const);
+
+ n->val.type = T_BitString;
+ n->val.val.str = str;
+
+ return (Node *)n;
+}
+
+static Node *
+makeNullAConst(void)
+{
+ A_Const *n = makeNode(A_Const);
+
+ n->val.type = T_Null;
+
+ return (Node *)n;
}
static Node *
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_type.c,v 1.96 2008/04/29 14:59:17 alvherre Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_type.c,v 1.97 2008/04/29 20:44:49 tgl Exp $
*
*-------------------------------------------------------------------------
*/
cstr = (char *) palloc(32);
snprintf(cstr, 32, "%ld", (long) ac->val.val.ival);
}
- else
+ else if (IsA(&ac->val, Float) ||
+ IsA(&ac->val, String))
+ {
/* we can just use the str field directly. */
cstr = ac->val.val.str;
- }
- else if (IsA(tm, TypeCast))
- {
- /*
- * The grammar hands back some integers with ::int4 attached, so
- * allow a cast decoration if it's an Integer value, but not
- * otherwise.
- */
- TypeCast *tc = (TypeCast *) tm;
-
- if (IsA(tc->arg, A_Const))
- {
- A_Const *ac = (A_Const *) tc->arg;
-
- if (IsA(&ac->val, Integer))
- {
- cstr = (char *) palloc(32);
- snprintf(cstr, 32, "%ld", (long) ac->val.val.ival);
- }
}
}
else if (IsA(tm, ColumnRef))
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.448 2008/04/29 14:59:17 alvherre Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.449 2008/04/29 20:44:49 tgl Exp $
*
*--------------------------------------------------------------------
*/
/*
* Each list member may be a plain A_Const node, or an A_Const within a
- * TypeCast, as produced by makeFloatConst() et al in gram.y.
+ * TypeCast; the latter case is supported only for ConstInterval
+ * arguments (for SET TIME ZONE).
*/
foreach(l, args)
{
if (!IsA(arg, A_Const))
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
-
con = (A_Const *) arg;
+
switch (nodeTag(&con->val))
{
case T_Integer:
appendStringInfoString(&buf, strVal(&con->val));
break;
case T_String:
- /*
- * Plain string literal or identifier. For quote mode,
- * quote it if it's not a vanilla identifier.
- */
val = strVal(&con->val);
if (typename != NULL)
{
DatumGetCString(DirectFunctionCall1(interval_out,
interval));
appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
-
- /* don't leave this set */
- typename = NULL;
}
else
{
+ /*
+ * Plain string literal or identifier. For quote mode,
+ * quote it if it's not a vanilla identifier.
+ */
if (flags & GUC_LIST_QUOTE)
appendStringInfoString(&buf, quote_identifier(val));
else