*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.23 1997/03/12 20:51:33 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.24 1997/04/02 04:00:55 vadim Exp $
*
*-------------------------------------------------------------------------
*/
#include "utils/palloc.h"
#include "utils/mcxt.h"
#include "utils/syscache.h"
+#include "utils/acl.h"
#include "parser/parse_query.h"
#include "parser/parse_state.h"
#include "nodes/makefuncs.h" /* for makeResdom(), etc. */
#include "nodes/nodeFuncs.h"
+#include "commands/sequence.h"
#include "optimizer/clauses.h"
#include "access/heapam.h"
+#include "miscadmin.h"
+
#include "port-protos.h" /* strdup() */
/* convert the parse tree into a query tree */
static TargetEntry *make_targetlist_expr(ParseState *pstate,
char *colname, Node *expr,
List *arrayRef);
+static bool inWhereClause = false;
static Node *transformWhereClause(ParseState *pstate, Node *a_expr);
static List *transformGroupClause(ParseState *pstate, List *grouplist,
List *targetlist);
result = malloc(sizeof(QueryTreeList));
result->len = length(pl);
result->qtrees = (Query**)malloc(result->len * sizeof(Query*));
+
+ inWhereClause = false; /* to avoid nextval(sequence) in WHERE */
while(pl!=NIL) {
pstate = makeParseState();
if (a_expr == NULL)
return (Node *)NULL; /* no qualifiers */
+ inWhereClause = true;
qual = transformExpr(pstate, a_expr, EXPR_COLUMN_FIRST);
+ inWhereClause = false;
if (exprType(qual) != BOOLOID) {
elog(WARN,
"where clause must return type bool, not %s",
}
}
+ /*
+ * Sequence handling.
+ */
+ if ( funcid == SeqNextValueRegProcedure ||
+ funcid == SeqCurrValueRegProcedure )
+ {
+ Const *seq;
+ char *seqrel;
+ int32 aclcheck_result = -1;
+
+ Assert ( length(fargs) == 1 );
+ seq = (Const*)lfirst(fargs);
+ if ( ! IsA ((Node*)seq, Const) )
+ elog (WARN, "%s: only constant sequence names are acceptable", funcname);
+ seqrel = textout ((struct varlena *) (seq->constvalue));
+
+ if ( ( aclcheck_result = pg_aclcheck (seqrel, GetPgUserName(),
+ ((funcid == SeqNextValueRegProcedure) ? ACL_WR : ACL_RD)) )
+ != ACLCHECK_OK )
+ elog (WARN, "%s.%s: %s",
+ seqrel, funcname, aclcheck_error_strings[aclcheck_result]);
+
+ pfree (seqrel);
+
+ if ( funcid == SeqNextValueRegProcedure && inWhereClause )
+ elog (WARN, "nextval of a sequence in WHERE disallowed");
+ }
+
expr = makeNode(Expr);
expr->typeOid = rettype;
expr->opType = FUNC_EXPR;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.27 1997/03/26 02:52:49 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.28 1997/04/02 04:01:03 vadim Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
%type <node> stmt,
AddAttrStmt, ClosePortalStmt,
- CopyStmt, CreateStmt, DefineStmt, DestroyStmt,
+ CopyStmt, CreateStmt, CreateSeqStmt, DefineStmt, DestroyStmt,
ExtendStmt, FetchStmt, GrantStmt,
IndexStmt, MoveStmt, ListenStmt, OptimizableStmt,
ProcedureStmt, PurgeStmt,
%type <ival> OptLocation, opt_move_where, fetch_how_many
+%type <list> OptSeqList
+%type <defelt> OptSeqElem
+
%type <dstmt> def_rest
%type <pstmt> purge_quals
%type <astmt> insert_rest
SELECT, SET, SETOF, STDIN, STDOUT, STORE,
TABLE, TO, TRANSACTION, UNIQUE, UPDATE, USING, VACUUM, VALUES
VERBOSE, VERSION, VIEW, WHERE, WITH, WORK
-%token EXECUTE, RECIPE, EXPLAIN, LIKE
+%token EXECUTE, RECIPE, EXPLAIN, LIKE, SEQUENCE
/* Special keywords, not in the query language - see the "lex" file */
%token <str> IDENT, SCONST, Op
| ClosePortalStmt
| CopyStmt
| CreateStmt
+ | CreateSeqStmt
| ClusterStmt
| DefineStmt
| DestroyStmt
;
+/*****************************************************************************
+ *
+ * QUERY :
+ * CREATE SEQUENCE seqname
+ *
+ *****************************************************************************/
+
+CreateSeqStmt: CREATE SEQUENCE relation_name OptSeqList
+ {
+ CreateSeqStmt *n = makeNode(CreateSeqStmt);
+ n->seqname = $3;
+ n->options = $4;
+ $$ = (Node *)n;
+ }
+ ;
+
+OptSeqList:
+ OptSeqList OptSeqElem
+ { $$ = lappend($1, $2); }
+ | { $$ = NIL; }
+ ;
+
+OptSeqElem: IDENT NumConst
+ {
+ $$ = makeNode(DefElem);
+ $$->defname = $1;
+ $$->arg = (Node *)$2;
+ }
+ | IDENT
+ {
+ $$ = makeNode(DefElem);
+ $$->defname = $1;
+ $$->arg = (Node *)NULL;
+ }
+ ;
+
+
/*****************************************************************************
*
* QUERY :
*
*****************************************************************************/
-DestroyStmt: DROP TABLE relation_name_list
+DestroyStmt: DROP TABLE relation_name_list
+ {
+ DestroyStmt *n = makeNode(DestroyStmt);
+ n->relNames = $3;
+ n->sequence = false;
+ $$ = (Node *)n;
+ }
+ | DROP SEQUENCE relation_name_list
{
DestroyStmt *n = makeNode(DestroyStmt);
n->relNames = $3;
+ n->sequence = true;
$$ = (Node *)n;
}
;