Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
4527172b
Commit
4527172b
authored
Aug 20, 1997
by
Vadim B. Mikheev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CHECK/DEFAULT syntax
parent
bb951c6c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
163 additions
and
25 deletions
+163
-25
src/backend/parser/gram.y
src/backend/parser/gram.y
+156
-22
src/backend/parser/keywords.c
src/backend/parser/keywords.c
+3
-1
src/include/nodes/parsenodes.h
src/include/nodes/parsenodes.h
+4
-2
No files found.
src/backend/parser/gram.y
View file @
4527172b
...
...
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.3
6 1997/08/19 04:44:01
vadim Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.3
7 1997/08/20 01:12:02
vadim Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
...
...
@@ -49,6 +49,11 @@ static bool QueryIsRule = FALSE;
static Node *saved_In_Expr;
extern List *parsetree;
extern int CurScanPosition(void);
extern int DefaultStartPosition;
extern int CheckStartPosition;
extern char *parseString;
/*
* If you need access to certain yacc-generated variables and find that
* they're static by default, uncomment the next line. (this is not a
...
...
@@ -113,7 +118,7 @@ static Node *makeA_Expr(int oper, char *opname, Node *lexpr, Node *rexpr);
%type <str> relation_name, copy_file_name, copy_delimiter, def_name,
database_name, access_method_clause, access_method, attr_name,
class, index_name, name, file_name, recipe_name,
var_name, aggr_argtype
var_name, aggr_argtype
, OptDefault, CheckElem
%type <str> opt_id, opt_portal_name,
before_clause, after_clause, all_Op, MathOp, opt_name, opt_unique,
...
...
@@ -124,14 +129,14 @@ static Node *makeA_Expr(int oper, char *opname, Node *lexpr, Node *rexpr);
%type <chr> operation
%type <list> stmtblock, stmtmulti,
relation_name_list, OptTableElementList,
tableElementList, OptInheri
t, definition,
relation_name_list, OptTableElementList,
tableElementList,
OptInherit, OptCheck, CheckLis
t, definition,
opt_with, def_args, def_name_list, func_argtypes,
oper_argtypes, OptStmtList, OptStmtBlock, OptStmtMulti,
opt_column_list, columnList, opt_va_list, va_list,
sort_clause, sortby_list, index_params, index_list,
name_list,
from_clause, from_list, opt_array_bounds, nest_array_bounds,
expr_list, attrs, res_target_list, res_target_list2,
sort_clause, sortby_list, index_params, index_list,
name_list,
from_clause, from_list, opt_array_bounds, nest_array_bounds,
expr_list,
default_expr_list,
attrs, res_target_list, res_target_list2,
def_list, opt_indirection, group_clause, groupby_list
%type <boolean> opt_inh_star, opt_binary, opt_instead, opt_with_copy,
...
...
@@ -154,8 +159,9 @@ static Node *makeA_Expr(int oper, char *opname, Node *lexpr, Node *rexpr);
%type <defelt> def_elem
%type <node> def_arg, columnElem, where_clause,
a_expr, a_expr_or_null, AexprConst,
default_expr, default_expr_or_null,
in_expr_nodes, not_in_expr_nodes,
having_clause
having_clause
, default_expr
%type <value> NumConst
%type <attr> event_object, attr
%type <sortgroupby> groupby
...
...
@@ -182,9 +188,9 @@ static Node *makeA_Expr(int oper, char *opname, Node *lexpr, Node *rexpr);
%token ABORT_TRANS, ACL, ADD, AFTER, AGGREGATE, ALL, ALTER, ANALYZE,
AND, APPEND, ARCHIVE, ARCH_STORE, AS, ASC,
BACKWARD, BEFORE, BEGIN_TRANS, BETWEEN, BINARY, BY,
CAST, CHANGE, CLOSE, CLUSTER, COLUMN, COMMIT, COPY, CREATE,
CURRENT, CURSOR, DATABASE, DECLARE, DE
LETE, DELIMITERS, DESC
,
DISTINCT, DO, DROP, END_TRANS,
CAST, CHANGE, C
HECK, C
LOSE, CLUSTER, COLUMN, COMMIT, COPY, CREATE,
CURRENT, CURSOR, DATABASE, DECLARE, DE
FAULT, DELETE
,
D
ELIMITERS, DESC, D
ISTINCT, DO, DROP, END_TRANS,
EXTEND, FETCH, FOR, FORWARD, FROM, FUNCTION, GRANT, GROUP,
HAVING, HEAVY, IN, INDEX, INHERITS, INSERT, INSTEAD, INTO, IS,
ISNULL, LANGUAGE, LIGHT, LISTEN, LOAD, MERGE, MOVE, NEW,
...
...
@@ -333,20 +339,123 @@ AddAttrStmt: ALTER TABLE relation_name opt_inh_star ADD COLUMN columnDef
}
;
columnDef: Id Typename opt_null
columnDef: Id Typename
OptDefault
opt_null
{
$$ = makeNode(ColumnDef);
$$->colname = $1;
$$->typename = $2;
$$->is_not_null = $3;
$$->defval = $3;
$$->is_not_null = $4;
}
;
opt_null: PNULL { $$ = false; }
| NOT PNULL { $$ = true; }
| NOTNULL { $$ = true; }
| /* EMPTY */ { $$ = false; }
;
OptDefault: DEFAULT default_expr {
int deflen = CurScanPosition() - DefaultStartPosition;
char *defval;
defval = (char*) palloc (deflen + 1);
memcpy (defval,
parseString + DefaultStartPosition,
deflen);
defval[deflen] = 0;
$$ = defval;
}
| /*EMPTY*/ { $$ = NULL; }
;
default_expr_or_null: default_expr
{ $$ = $1;}
| Pnull
{
A_Const *n = makeNode(A_Const);
n->val.type = T_Null;
$$ = (Node *)n;
}
default_expr: AexprConst
{
if (nodeTag($1) != T_A_Const)
elog (WARN, "Cannot handle parameter in DEFAULT");
$$ = $1;
}
| '-' default_expr %prec UMINUS
{ $$ = makeA_Expr(OP, "-", NULL, $2); }
| default_expr '+' default_expr
{ $$ = makeA_Expr(OP, "+", $1, $3); }
| default_expr '-' default_expr
{ $$ = makeA_Expr(OP, "-", $1, $3); }
| default_expr '/' default_expr
{ $$ = makeA_Expr(OP, "/", $1, $3); }
| default_expr '*' default_expr
{ $$ = makeA_Expr(OP, "*", $1, $3); }
| default_expr '<' default_expr
{ $$ = makeA_Expr(OP, "<", $1, $3); }
| default_expr '>' default_expr
{ $$ = makeA_Expr(OP, ">", $1, $3); }
| default_expr '=' default_expr
{ $$ = makeA_Expr(OP, "=", $1, $3); }
| ':' default_expr
{ $$ = makeA_Expr(OP, ":", NULL, $2); }
| ';' default_expr
{ $$ = makeA_Expr(OP, ";", NULL, $2); }
| '|' default_expr
{ $$ = makeA_Expr(OP, "|", NULL, $2); }
| AexprConst TYPECAST Typename
{
/* AexprConst can be either A_Const or ParamNo */
if (nodeTag($1) == T_A_Const) {
((A_Const *)$1)->typename = $3;
}else {
elog (WARN, "Cannot handle parameter in DEFAULT");
}
$$ = (Node *)$1;
}
| CAST AexprConst AS Typename
{
/* AexprConst can be either A_Const or ParamNo */
if (nodeTag($2) == T_A_Const) {
((A_Const *)$2)->typename = $4;
}else {
elog (WARN, "Cannot handle parameter in DEFAULT");
}
$$ = (Node *)$2;
}
| '(' default_expr ')'
{ $$ = $2; }
| default_expr Op default_expr
{ $$ = makeA_Expr(OP, $2, $1, $3); }
| Op default_expr
{ $$ = makeA_Expr(OP, $1, NULL, $2); }
| default_expr Op
{ $$ = makeA_Expr(OP, $2, $1, NULL); }
| name '(' ')'
{
FuncCall *n = makeNode(FuncCall);
n->funcname = $1;
n->args = NIL;
$$ = (Node *)n;
}
| name '(' default_expr_list ')'
{
FuncCall *n = makeNode(FuncCall);
n->funcname = $1;
n->args = $3;
$$ = (Node *)n;
}
;
default_expr_list: default_expr_or_null
{ $$ = lcons($1, NIL); }
| default_expr_list ',' default_expr_or_null
{ $$ = lappend($1, $3); }
;
opt_null: PNULL { $$ = false; }
| NOT PNULL { $$ = true; }
| NOTNULL { $$ = true; }
| /* EMPTY */ { $$ = false; }
;
/*****************************************************************************
*
...
...
@@ -425,15 +534,17 @@ copy_delimiter: USING DELIMITERS Sconst { $$ = $3;}
*****************************************************************************/
CreateStmt: CREATE TABLE relation_name '(' OptTableElementList ')'
OptInherit OptArchiveType OptLocation OptArchiveLocation
OptInherit OptCheck OptArchiveType OptLocation
OptArchiveLocation
{
CreateStmt *n = makeNode(CreateStmt);
n->relname = $3;
n->tableElts = $5;
n->inhRelnames = $7;
n->archiveType = $8;
n->location = $9;
n->archiveLoc = $10;
n->check = $8;
n->archiveType = $9;
n->location = $10;
n->archiveLoc = $11;
$$ = (Node *)n;
}
;
...
...
@@ -475,6 +586,29 @@ OptInherit: INHERITS '(' relation_name_list ')' { $$ = $3; }
| /*EMPTY*/ { $$ = NIL; }
;
OptCheck: CheckList { $$ = $1; }
| { $$ = NULL; }
;
CheckList :
CheckList ',' CheckElem
{ $$ = lappend($1, $3); }
| CheckElem
{ $$ = lcons($1, NIL); }
;
CheckElem: CHECK a_expr {
int chklen = CurScanPosition() - CheckStartPosition;
char *check;
check = (char*) palloc (chklen + 1);
memcpy (check,
parseString + CheckStartPosition,
chklen);
check[chklen] = 0;
$$ = check;
}
;
/*****************************************************************************
*
...
...
src/backend/parser/keywords.c
View file @
4527172b
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.1
0 1997/04/23 06:04:46
vadim Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.1
1 1997/08/20 01:12:04
vadim Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -54,6 +54,7 @@ static ScanKeyword ScanKeywords[] = {
{
"by"
,
BY
},
{
"cast"
,
CAST
},
{
"change"
,
CHANGE
},
{
"check"
,
CHECK
},
{
"close"
,
CLOSE
},
{
"cluster"
,
CLUSTER
},
{
"column"
,
COLUMN
},
...
...
@@ -64,6 +65,7 @@ static ScanKeyword ScanKeywords[] = {
{
"cursor"
,
CURSOR
},
{
"database"
,
DATABASE
},
{
"declare"
,
DECLARE
},
{
"default"
,
DEFAULT
},
{
"delete"
,
DELETE
},
{
"delimiters"
,
DELIMITERS
},
{
"desc"
,
DESC
},
...
...
src/include/nodes/parsenodes.h
View file @
4527172b
...
...
@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: parsenodes.h,v 1.1
7 1997/08/19 04:46:15
vadim Exp $
* $Id: parsenodes.h,v 1.1
8 1997/08/20 01:12:38
vadim Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -136,6 +136,7 @@ typedef struct CreateStmt {
ArchType
archiveType
;
/* archive mode (ARCH_NONE if none */
int
location
;
/* smgrid (-1 if none) */
int
archiveLoc
;
/* smgrid (-1 if none) */
List
*
check
;
/* list of CHECK constr */
}
CreateStmt
;
/* ----------------------
...
...
@@ -607,7 +608,8 @@ typedef struct ColumnDef {
NodeTag
type
;
char
*
colname
;
/* name of column */
TypeName
*
typename
;
/* type of column */
bool
is_not_null
;
/* flag to NOT NULL constraint */
bool
is_not_null
;
/* flag to NOT NULL constraint */
char
*
defval
;
/* default value of column */
}
ColumnDef
;
/*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment