*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.311 2002/05/02 18:44:10 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.312 2002/05/03 00:32:16 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
%type <range> relation_expr
%type <target> target_el, insert_target_el, update_target_el
-%type <typnam> Typename, SimpleTypename, ConstTypename
- GenericType, Numeric, Character, ConstDatetime, ConstInterval, Bit
-%type <str> character, bit
+%type <typnam> Typename, SimpleTypename, ConstTypename,
+ GenericType, Numeric, opt_float, Character,
+ ConstDatetime, ConstInterval, Bit
+%type <str> character
%type <str> extract_arg
%type <str> opt_charset, opt_collate
-%type <str> opt_float
%type <ival> opt_numeric, opt_decimal
%type <boolean> opt_varying, opt_timezone
ELSE, ENCRYPTED, END_TRANS, ESCAPE, EXCEPT, EXECUTE, EXISTS, EXTRACT,
FALSE_P, FETCH, FLOAT, FOR, FOREIGN, FROM, FULL,
GLOBAL, GRANT, GROUP, HAVING, HOUR_P,
- IN, INNER_P, INSENSITIVE, INSERT, INTERSECT, INTERVAL, INTO, IS,
- ISOLATION, JOIN, KEY, LANGUAGE, LEADING, LEFT, LEVEL, LIKE, LOCAL,
+ IN, INNER_P, INSENSITIVE, INSERT, INT, INTEGER, INTERSECT, INTERVAL,
+ INTO, IS, ISOLATION,
+ JOIN, KEY, LANGUAGE, LEADING, LEFT, LEVEL, LIKE, LOCAL,
MATCH, MINUTE_P, MONTH_P, NAMES,
NATIONAL, NATURAL, NCHAR, NEXT, NO, NOT, NULLIF, NULL_P, NUMERIC,
OF, OLD, ON, ONLY, OPTION, OR, ORDER, OUTER_P, OVERLAPS,
PARTIAL, POSITION, PRECISION, PRIMARY, PRIOR, PRIVILEGES, PROCEDURE,
- READ, REFERENCES, RELATIVE, REVOKE, RIGHT, ROLLBACK,
- SCHEMA, SCROLL, SECOND_P, SELECT, SESSION, SESSION_USER, SET, SOME, SUBSTRING,
+ READ, REAL, REFERENCES, RELATIVE, REVOKE, RIGHT, ROLLBACK,
+ SCHEMA, SCROLL, SECOND_P, SELECT, SESSION, SESSION_USER, SET,
+ SMALLINT, SOME, SUBSTRING,
TABLE, TEMPORARY, THEN, TIME, TIMESTAMP,
TO, TRAILING, TRANSACTION, TRIM, TRUE_P,
UNENCRYPTED, UNION, UNIQUE, UNKNOWN, UPDATE, USAGE, USER, USING,
WHEN, WHERE, WITH, WORK, YEAR_P, ZONE
/* Keywords (in SQL99 reserved words) */
-%token <keyword> ASSERTION, CHAIN, CHARACTERISTICS,
+%token <keyword> ASSERTION, BINARY, BIT, BOOLEAN,
+ CHAIN, CHARACTERISTICS,
DEFERRABLE, DEFERRED,
IMMEDIATE, INITIALLY, INOUT,
OFF, OUT,
* - Todd A. Brandys 1998-01-01?
*/
%token <keyword> ABORT_TRANS, ACCESS, AFTER, AGGREGATE, ANALYSE, ANALYZE,
- BACKWARD, BEFORE, BINARY, BIT,
+ BACKWARD, BEFORE, BIGINT,
CACHE, CHECKPOINT, CLUSTER, COMMENT, COPY, CREATEDB, CREATEUSER, CYCLE,
DATABASE, DELIMITERS, DO,
EACH, ENCODING, EXCLUSIVE, EXPLAIN,
GenericType: type_name
{
- $$ = makeTypeName(xlateSqlType($1));
+ $$ = makeTypeName($1);
}
;
* Provide real DECIMAL() and NUMERIC() implementations now - Jan 1998-12-30
* - thomas 1997-09-18
*/
-Numeric: FLOAT opt_float
+Numeric: INT
+ {
+ $$ = SystemTypeName("int4");
+ }
+ | INTEGER
+ {
+ $$ = SystemTypeName("int4");
+ }
+ | SMALLINT
+ {
+ $$ = SystemTypeName("int2");
+ }
+ | BIGINT
+ {
+ $$ = SystemTypeName("int8");
+ }
+ | REAL
+ {
+ $$ = SystemTypeName("float4");
+ }
+ | FLOAT opt_float
{
- $$ = makeTypeName($2); /* already xlated */
+ $$ = $2;
}
| DOUBLE PRECISION
{
- $$ = makeTypeName(xlateSqlType("float8"));
+ $$ = SystemTypeName("float8");
}
| DECIMAL opt_decimal
{
- $$ = makeTypeName(xlateSqlType("decimal"));
+ $$ = SystemTypeName("numeric");
$$->typmod = $2;
}
| DEC opt_decimal
{
- $$ = makeTypeName(xlateSqlType("decimal"));
+ $$ = SystemTypeName("numeric");
$$->typmod = $2;
}
| NUMERIC opt_numeric
{
- $$ = makeTypeName(xlateSqlType("numeric"));
+ $$ = SystemTypeName("numeric");
$$->typmod = $2;
}
+ | BOOLEAN
+ {
+ $$ = SystemTypeName("bool");
+ }
;
opt_float: '(' Iconst ')'
if ($2 < 1)
elog(ERROR, "precision for FLOAT must be at least 1");
else if ($2 < 7)
- $$ = xlateSqlType("float4");
+ $$ = SystemTypeName("float4");
else if ($2 < 16)
- $$ = xlateSqlType("float8");
+ $$ = SystemTypeName("float8");
else
elog(ERROR, "precision for FLOAT must be less than 16");
}
| /*EMPTY*/
{
- $$ = xlateSqlType("float8");
+ $$ = SystemTypeName("float8");
}
;
* SQL92 bit-field data types
* The following implements BIT() and BIT VARYING().
*/
-Bit: bit '(' Iconst ')'
+Bit: BIT opt_varying '(' Iconst ')'
{
- $$ = makeTypeName($1);
- if ($3 < 1)
+ char *typname;
+
+ typname = $2 ? "varbit" : "bit";
+ $$ = SystemTypeName(typname);
+ if ($4 < 1)
elog(ERROR, "length for type '%s' must be at least 1",
- $1);
- else if ($3 > (MaxAttrSize * BITS_PER_BYTE))
+ typname);
+ else if ($4 > (MaxAttrSize * BITS_PER_BYTE))
elog(ERROR, "length for type '%s' cannot exceed %d",
- $1, (MaxAttrSize * BITS_PER_BYTE));
- $$->typmod = $3;
+ typname, (MaxAttrSize * BITS_PER_BYTE));
+ $$->typmod = $4;
}
- | bit
+ | BIT opt_varying
{
- $$ = makeTypeName($1);
/* bit defaults to bit(1), varbit to no limit */
- if (strcmp($1, "bit") == 0)
- $$->typmod = 1;
- else
+ if ($2)
+ {
+ $$ = SystemTypeName("varbit");
$$->typmod = -1;
- }
- ;
-
-bit: BIT opt_varying
- {
- char *type;
-
- if ($2) type = xlateSqlType("varbit");
- else type = xlateSqlType("bit");
- $$ = type;
+ }
+ else
+ {
+ $$ = SystemTypeName("bit");
+ $$->typmod = 1;
+ }
}
;
strcpy(type, $1);
strcat(type, "_");
strcat(type, $5);
- $1 = xlateSqlType(type);
+ $1 = type;
}
- $$ = makeTypeName($1);
+ $$ = SystemTypeName($1);
if ($3 < 1)
elog(ERROR, "length for type '%s' must be at least 1",
strcpy(type, $1);
strcat(type, "_");
strcat(type, $2);
- $1 = xlateSqlType(type);
+ $1 = type;
}
- $$ = makeTypeName($1);
+ $$ = SystemTypeName($1);
/* char defaults to char(1), varchar to no limit */
if (strcmp($1, "bpchar") == 0)
}
;
-character: CHARACTER opt_varying { $$ = xlateSqlType($2 ? "varchar": "bpchar"); }
- | CHAR opt_varying { $$ = xlateSqlType($2 ? "varchar": "bpchar"); }
- | VARCHAR { $$ = xlateSqlType("varchar"); }
- | NATIONAL CHARACTER opt_varying { $$ = xlateSqlType($3 ? "varchar": "bpchar"); }
- | NATIONAL CHAR opt_varying { $$ = xlateSqlType($3 ? "varchar": "bpchar"); }
- | NCHAR opt_varying { $$ = xlateSqlType($2 ? "varchar": "bpchar"); }
+character: CHARACTER opt_varying { $$ = $2 ? "varchar": "bpchar"; }
+ | CHAR opt_varying { $$ = $2 ? "varchar": "bpchar"; }
+ | VARCHAR { $$ = "varchar"; }
+ | NATIONAL CHARACTER opt_varying { $$ = $3 ? "varchar": "bpchar"; }
+ | NATIONAL CHAR opt_varying { $$ = $3 ? "varchar": "bpchar"; }
+ | NCHAR opt_varying { $$ = $2 ? "varchar": "bpchar"; }
;
opt_varying: VARYING { $$ = TRUE; }
ConstDatetime: TIMESTAMP '(' Iconst ')' opt_timezone
{
if ($5)
- $$ = makeTypeName(xlateSqlType("timestamptz"));
+ $$ = SystemTypeName("timestamptz");
else
- $$ = makeTypeName(xlateSqlType("timestamp"));
+ $$ = SystemTypeName("timestamp");
/* XXX the timezone field seems to be unused
* - thomas 2001-09-06
*/
| TIMESTAMP opt_timezone
{
if ($2)
- $$ = makeTypeName(xlateSqlType("timestamptz"));
+ $$ = SystemTypeName("timestamptz");
else
- $$ = makeTypeName(xlateSqlType("timestamp"));
+ $$ = SystemTypeName("timestamp");
/* XXX the timezone field seems to be unused
* - thomas 2001-09-06
*/
| TIME '(' Iconst ')' opt_timezone
{
if ($5)
- $$ = makeTypeName(xlateSqlType("timetz"));
+ $$ = SystemTypeName("timetz");
else
- $$ = makeTypeName(xlateSqlType("time"));
+ $$ = SystemTypeName("time");
if (($3 < 0) || ($3 > MAX_TIME_PRECISION))
elog(ERROR, "TIME(%d)%s precision must be between %d and %d",
$3, ($5 ? " WITH TIME ZONE": ""), 0, MAX_TIME_PRECISION);
| TIME opt_timezone
{
if ($2)
- $$ = makeTypeName(xlateSqlType("timetz"));
+ $$ = SystemTypeName("timetz");
else
- $$ = makeTypeName(xlateSqlType("time"));
+ $$ = SystemTypeName("time");
/* SQL99 specified a default precision of zero.
* See comments for timestamp above on why we will
* leave this unspecified for now. - thomas 2001-12-07
ConstInterval: INTERVAL
{
- $$ = makeTypeName(xlateSqlType("interval"));
+ $$ = SystemTypeName("interval");
}
;
s->val.type = T_String;
s->val.val.str = "now";
- s->typename = makeTypeName(xlateSqlType("text"));
+ s->typename = SystemTypeName("text");
- d = makeTypeName(xlateSqlType("date"));
+ d = SystemTypeName("date");
$$ = (Node *)makeTypeCast((Node *)s, d);
}
s->val.type = T_String;
s->val.val.str = "now";
- s->typename = makeTypeName(xlateSqlType("text"));
+ s->typename = SystemTypeName("text");
- d = makeTypeName(xlateSqlType("timetz"));
+ d = SystemTypeName("timetz");
/* SQL99 mandates a default precision of zero for TIME
* fields in schemas. However, for CURRENT_TIME
* let's preserve the microsecond precision we
s->val.type = T_String;
s->val.val.str = "now";
- s->typename = makeTypeName(xlateSqlType("text"));
- d = makeTypeName(xlateSqlType("timetz"));
+ s->typename = SystemTypeName("text");
+ d = SystemTypeName("timetz");
if (($3 < 0) || ($3 > MAX_TIME_PRECISION))
elog(ERROR, "CURRENT_TIME(%d) precision must be between %d and %d",
$3, 0, MAX_TIME_PRECISION);
s->val.type = T_String;
s->val.val.str = "now";
- s->typename = makeTypeName(xlateSqlType("text"));
+ s->typename = SystemTypeName("text");
- d = makeTypeName(xlateSqlType("timestamptz"));
+ d = SystemTypeName("timestamptz");
/* SQL99 mandates a default precision of 6 for timestamp.
* Also, that is about as precise as we will get since
* we are using a microsecond time interface.
s->val.type = T_String;
s->val.val.str = "now";
- s->typename = makeTypeName(xlateSqlType("text"));
+ s->typename = SystemTypeName("text");
- d = makeTypeName(xlateSqlType("timestamptz"));
+ d = SystemTypeName("timestamptz");
if (($3 < 0) || ($3 > MAX_TIMESTAMP_PRECISION))
elog(ERROR, "CURRENT_TIMESTAMP(%d) precision must be between %d and %d",
$3, 0, MAX_TIMESTAMP_PRECISION);
file_name: Sconst { $$ = $1; };
func_name: function_name
- { $$ = makeList1(makeString(xlateSqlFunc($1))); }
+ { $$ = makeList1(makeString($1)); }
| dotted_name
{ $$ = $1; }
;
A_Const *n = makeNode(A_Const);
n->val.type = T_String;
n->val.val.str = "t";
- n->typename = makeTypeName(xlateSqlType("bool"));
+ n->typename = SystemTypeName("bool");
$$ = (Node *)n;
}
| FALSE_P
A_Const *n = makeNode(A_Const);
n->val.type = T_String;
n->val.val.str = "f";
- n->typename = makeTypeName(xlateSqlType("bool"));
+ n->typename = SystemTypeName("bool");
$$ = (Node *)n;
}
| NULL_P
* looks too much like a function call for an LR(1) parser.
*/
col_name_keyword:
- BIT
+ BIGINT
+ | BIT
+ | BOOLEAN
| CHAR
| CHARACTER
| COALESCE
| EXISTS
| EXTRACT
| FLOAT
+ | INT
+ | INTEGER
| INTERVAL
| NCHAR
| NONE
| NULLIF
| NUMERIC
| POSITION
+ | REAL
| SETOF
+ | SMALLINT
| SUBSTRING
| TIME
| TIMESTAMP
A_Const *n = makeNode(A_Const);
n->val.type = T_Integer;
n->val.val.ival = val;
- n->typename = makeTypeName(xlateSqlType("integer"));
+ n->typename = SystemTypeName("int4");
return (Node *)n;
}
n->val.type = T_Float;
n->val.val.str = str;
- n->typename = makeTypeName(xlateSqlType("float"));
+ n->typename = SystemTypeName("float8");
return (Node *)n;
}
return (Node *) n;
}
-/* xlateSqlFunc()
- * Convert alternate function names to internal Postgres functions.
- *
- * NOTE: these conversions are only applied to unqualified function names.
- *
- * Do not convert "float", since that is handled elsewhere
- * for FLOAT(p) syntax.
- *
- * Converting "datetime" to "timestamp" and "timespan" to "interval"
- * is a temporary expedient for pre-7.0 to 7.0 compatibility;
- * these should go away for v7.1.
- */
-char *
-xlateSqlFunc(char *name)
-{
- if (strcmp(name,"character_length") == 0)
- return "char_length";
- else if (strcmp(name,"datetime") == 0)
- return "timestamp";
- else if (strcmp(name,"timespan") == 0)
- return "interval";
- else
- return name;
-} /* xlateSqlFunc() */
-
-/* xlateSqlType()
- * Convert alternate type names to internal Postgres types.
- *
- * NOTE: these conversions are only applied to unqualified type names.
- *
- * NB: do NOT put "char" -> "bpchar" here, because that renders it impossible
- * to refer to our single-byte char type, even with quotes. (Without quotes,
- * CHAR is a keyword, and the code above produces "bpchar" for it.)
- *
- * Convert "datetime" and "timespan" to allow a transition to SQL92 type names.
- * Remove this translation for v7.1 - thomas 2000-03-25
- *
- * Convert "lztext" to "text" to allow forward compatibility for anyone using
- * the undocumented "lztext" type in 7.0. This can go away in 7.2 or later
- * - tgl 2000-07-30
- */
-char *
-xlateSqlType(char *name)
-{
- if ((strcmp(name,"int") == 0)
- || (strcmp(name,"integer") == 0))
- return "int4";
- else if (strcmp(name, "smallint") == 0)
- return "int2";
- else if (strcmp(name, "bigint") == 0)
- return "int8";
- else if (strcmp(name, "real") == 0)
- return "float4";
- else if (strcmp(name, "float") == 0)
- return "float8";
- else if (strcmp(name, "decimal") == 0)
- return "numeric";
- else if (strcmp(name, "datetime") == 0)
- return "timestamp";
- else if (strcmp(name, "timespan") == 0)
- return "interval";
- else if (strcmp(name, "lztext") == 0)
- return "text";
- else if (strcmp(name, "boolean") == 0)
- return "bool";
- else
- return name;
-} /* xlateSqlType() */
-
/* SystemFuncName()
* Build a properly-qualified reference to a built-in function.
*/
return makeList2(makeString("pg_catalog"), makeString(name));
}
-void parser_init(Oid *typev, int nargs)
+/* SystemTypeName()
+ * Build a properly-qualified reference to a built-in type.
+ *
+ * typmod is defaulted, but may be changed afterwards by caller.
+ */
+TypeName *
+SystemTypeName(char *name)
+{
+ TypeName *n = makeNode(TypeName);
+
+ n->names = makeList2(makeString("pg_catalog"), makeString(name));
+ n->typmod = -1;
+ return n;
+}
+
+/*
+ * Initialize to parse one query string
+ */
+void
+parser_init(Oid *typev, int nargs)
{
QueryIsRule = FALSE;
/*
pfunc_num_args = nargs;
}
-Oid param_type(int t)
+/*
+ * Fetch a parameter type previously passed to parser_init
+ */
+Oid
+param_type(int t)
{
if ((t > pfunc_num_args) || (t <= 0))
return InvalidOid;