1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-12 21:01:52 +03:00

Change the parser to convert SQL "position" and "substring" syntax to

position() and substring() functions, so that it works transparently for
bit types as well.  Alias the text functions appropriately.

Add position() for bit types.

Add new constant node T_BitString that represents literals of the form
B'1001 and pass those to zpbit type.
This commit is contained in:
Peter Eisentraut
2000-10-31 10:22:13 +00:00
parent d397c1c8a2
commit 73874a06f0
14 changed files with 214 additions and 47 deletions

View File

@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.201 2000/10/29 16:11:33 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.202 2000/10/31 10:22:10 petere Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@ -353,7 +353,7 @@ static void doNegateFloat(Value *v);
%token UNIONJOIN
/* Special keywords, not in the query language - see the "lex" file */
%token <str> IDENT, FCONST, SCONST, Op
%token <str> IDENT, FCONST, SCONST, BITCONST, Op
%token <ival> ICONST, PARAM
/* these are not real. they are here so that they get generated as #define's*/
@ -1798,6 +1798,10 @@ TriggerFuncArg: ICONST
{
$$ = makeString($1);
}
| BITCONST
{
$$ = makeString($1);
}
| ColId
{
$$ = makeString($1);
@ -4786,8 +4790,9 @@ c_expr: attr
}
| POSITION '(' position_list ')'
{
/* position(A in B) is converted to position(B, A) */
FuncCall *n = makeNode(FuncCall);
n->funcname = "strpos";
n->funcname = "position";
n->args = $3;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
@ -4795,8 +4800,10 @@ c_expr: attr
}
| SUBSTRING '(' substr_list ')'
{
/* substring(A from B for C) is converted to
* substring(A, B, C) */
FuncCall *n = makeNode(FuncCall);
n->funcname = "substr";
n->funcname = "substring";
n->args = $3;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
@ -5201,6 +5208,13 @@ AexprConst: Iconst
n->val.val.str = $1;
$$ = (Node *)n;
}
| BITCONST
{
A_Const *n = makeNode(A_Const);
n->val.type = T_BitString;
n->val.val.str = $1;
$$ = (Node *)n;
}
/* This rule formerly used Typename,
* but that causes reduce conflicts with subscripted column names.
* Now, separate into ConstTypename and ConstInterval,

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.47 2000/09/29 18:21:36 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.48 2000/10/31 10:22:11 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -31,6 +31,7 @@
#include "parser/parse_target.h"
#include "parser/parse_type.h"
#include "utils/builtins.h"
#include "utils/varbit.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
@ -473,6 +474,16 @@ make_const(Value *value)
typebyval = false;
break;
case T_BitString:
val = DirectFunctionCall3(zpbit_in,
CStringGetDatum(strVal(value)),
ObjectIdGetDatum(InvalidOid),
Int32GetDatum(-1));
typeid = ZPBITOID;
typelen = -1;
typebyval = false;
break;
default:
elog(NOTICE, "make_const: unknown type %d", nodeTag(value));
/* FALLTHROUGH */

View File

@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.79 2000/10/30 17:54:16 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.80 2000/10/31 10:22:11 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -93,25 +93,25 @@ static void addlit(char *ytext, int yleng);
* We use exclusive states for quoted strings, extended comments,
* and to eliminate parsing troubles for numeric strings.
* Exclusive states:
* <xb> binary numeric string - thomas 1997-11-16
* <xbit> bit string literal
* <xc> extended C-style comments - thomas 1997-07-12
* <xd> delimited identifiers (double-quoted identifiers) - thomas 1997-10-27
* <xh> hexadecimal numeric string - thomas 1997-11-16
* <xq> quoted strings - thomas 1997-07-30
*/
%x xb
%x xbit
%x xc
%x xd
%x xh
%x xq
/* Binary number
/* Bit string
*/
xbstart [bB]{quote}
xbstop {quote}
xbinside [^']+
xbcat {quote}{whitespace_with_newline}{quote}
xbitstart [bB]{quote}
xbitstop {quote}
xbitinside [^']*
xbitcat {quote}{whitespace_with_newline}{quote}
/* Hexadecimal number
*/
@ -279,30 +279,27 @@ other .
<xc><<EOF>> { elog(ERROR, "Unterminated /* comment"); }
{xbstart} {
BEGIN(xb);
{xbitstart} {
BEGIN(xbit);
startlit();
}
<xb>{xbstop} {
char* endptr;
<xbit>{xbitstop} {
BEGIN(INITIAL);
errno = 0;
yylval.ival = strtol(literalbuf, &endptr, 2);
if (*endptr != '\0' || errno == ERANGE)
elog(ERROR, "Bad binary integer input '%s'",
if (literalbuf[strspn(literalbuf, "01")] != '\0')
elog(ERROR, "invalid bit string input: '%s'",
literalbuf);
return ICONST;
yylval.str = literalbuf;
return BITCONST;
}
<xh>{xhinside} |
<xb>{xbinside} {
<xbit>{xbitinside} {
addlit(yytext, yyleng);
}
<xh>{xhcat} |
<xb>{xbcat} {
<xbit>{xbitcat} {
/* ignore */
}
<xb><<EOF>> { elog(ERROR, "Unterminated binary integer"); }
<xbit><<EOF>> { elog(ERROR, "unterminated bit string literal"); }
{xhstart} {
BEGIN(xh);