Add syntax for BIT() and BIT VARYING(), but no underlying implementation
authorThomas G. Lockhart
Tue, 21 Mar 2000 06:00:41 +0000 (06:00 +0000)
committerThomas G. Lockhart
Tue, 21 Mar 2000 06:00:41 +0000 (06:00 +0000)
 is available yet.
Remove redundant call to xlateSqlType() in the character
 type handling code.

src/backend/parser/gram.y
src/backend/parser/keywords.c

index a1172d404dbee992cf745c978fe0697f78de603a..4277f9c73661b9271a0e153b98fa2e263494a7e9 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.161 2000/03/20 05:20:34 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.162 2000/03/21 06:00:40 thomas Exp $
  *
  * HISTORY
  *   AUTHOR            DATE            MAJOR EVENT
@@ -249,8 +249,8 @@ static void doNegateFloat(Value *v);
 %type  ParamNo
 
 %type  Typename, opt_type, SimpleTypename,
-               Generic, Numeric, Character, Datetime
-%type         generic, numeric, character, datetime
+               Generic, Numeric, Character, Datetime, Bit
+%type         generic, numeric, character, datetime, bit
 %type         extract_arg
 %type         opt_charset, opt_collate
 %type         opt_float
@@ -334,7 +334,7 @@ static void doNegateFloat(Value *v);
  * - Todd A. Brandys 1998-01-01?
  */
 %token ABORT_TRANS, ACCESS, AFTER, AGGREGATE, ANALYZE,
-       BACKWARD, BEFORE, BINARY, 
+       BACKWARD, BEFORE, BINARY, BIT,
        CACHE, CLUSTER, COMMENT, COPY, CREATEDB, CREATEUSER, CYCLE,
        DATABASE, DELIMITERS, DO,
        EACH, ENCODING, EXCLUSIVE, EXPLAIN, EXTEND,
@@ -3766,6 +3766,7 @@ Typename:  SimpleTypename opt_array_bounds
 
 SimpleTypename:  Generic
        | Numeric
+       | Bit
        | Character
        | Datetime
        ;
@@ -3901,6 +3902,40 @@ opt_decimal:  '(' Iconst ',' Iconst ')'
        ;
 
 
+/*
+ * SQL92 bit-field data types
+ * The following implements BIT() and BIT VARYING().
+ */
+Bit:  bit '(' Iconst ')'
+               {
+                   $$ = makeNode(TypeName);
+                   $$->name = $1;
+                   if ($3 < 1)
+                       elog(ERROR,"length for type '%s' must be at least 1",$1);
+                   else if ($3 > (MaxAttrSize * sizeof(char)))
+                       elog(ERROR,"length for type '%s' cannot exceed %ld",$1,
+                            (MaxAttrSize * sizeof(char)));
+                   $$->typmod = $3;
+               }
+       | bit
+               {
+                   $$ = makeNode(TypeName);
+                   $$->name = $1;
+                   /* default length, if needed, will be inserted later */
+                   $$->typmod = -1;
+               }
+       ;
+
+bit:  BIT opt_varying
+               {
+                   char *type;
+
+                   if ($2) type = xlateSqlType("varbit");
+                   else type = xlateSqlType("bit");
+                   $$ = type;
+               }
+
+
 /*
  * SQL92 character data types
  * The following implements CHAR() and VARCHAR().
@@ -3908,12 +3943,12 @@ opt_decimal:  '(' Iconst ',' Iconst ')'
 Character:  character '(' Iconst ')'
                {
                    $$ = makeNode(TypeName);
-                   $$->name = xlateSqlType($1);
+                   $$->name = $1;
                    if ($3 < 1)
                        elog(ERROR,"length for type '%s' must be at least 1",$1);
                    else if ($3 > MaxAttrSize)
                        elog(ERROR,"length for type '%s' cannot exceed %ld",$1,
-                           MaxAttrSize);
+                            MaxAttrSize);
 
                    /* we actually implement these like a varlen, so
                     * the first 4 bytes is the length. (the difference
@@ -3925,7 +3960,7 @@ Character:  character '(' Iconst ')'
        | character
                {
                    $$ = makeNode(TypeName);
-                   $$->name = xlateSqlType($1);
+                   $$->name = $1;
                    /* default length, if needed, will be inserted later */
                    $$->typmod = -1;
                }
@@ -5198,9 +5233,12 @@ TypeId:  ColId
            {   $$ = xlateSqlType($1); }
        | numeric
            {   $$ = xlateSqlType($1); }
+       | bit
+           {   $$ = xlateSqlType($1); }
        | character
            {   $$ = xlateSqlType($1); }
        ;
+
 /* Column identifier
  * Include date/time keywords as SQL92 extension.
  * Include TYPE as a SQL92 unreserved keyword. - thomas 1997-10-05
@@ -5316,7 +5354,9 @@ ColLabel:  ColId                      { $$ = $1; }
        | ABORT_TRANS                   { $$ = "abort"; }
        | ANALYZE                       { $$ = "analyze"; }
        | BINARY                        { $$ = "binary"; }
+       | BIT                           { $$ = "bit"; }
        | CASE                          { $$ = "case"; }
+       | CHARACTER                     { $$ = "character"; }
        | CLUSTER                       { $$ = "cluster"; }
        | COALESCE                      { $$ = "coalesce"; }
        | CONSTRAINT                    { $$ = "constraint"; }
index 5bf703703d39037588b5a5b5cb97dc0a9a30d198..470a6c9523445ebbb7a3575ec4284f96854d5dc6 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.68 2000/03/14 23:06:32 thomas Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.69 2000/03/21 06:00:41 thomas Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -47,6 +47,7 @@ static ScanKeyword ScanKeywords[] = {
    {"begin", BEGIN_TRANS},
    {"between", BETWEEN},
    {"binary", BINARY},
+   {"bit", BIT},
    {"both", BOTH},
    {"by", BY},
    {"cache", CACHE},