]> granicus.if.org Git - postgresql/commitdiff
Fix a minor bug introduced by the recent CREATE TABLE AS / WITH OIDS
authorNeil Conway <neilc@samurai.com>
Fri, 23 Jan 2004 02:13:12 +0000 (02:13 +0000)
committerNeil Conway <neilc@samurai.com>
Fri, 23 Jan 2004 02:13:12 +0000 (02:13 +0000)
patch: a 3-value enum was mistakenly assigned directly to a 'bool'
in transformCreateStmt(). Along the way, change makeObjectName()
to be static, as it isn't used outside analyze.c

src/backend/commands/tablecmds.c
src/backend/parser/analyze.c
src/backend/parser/parse_clause.c
src/include/parser/analyze.h
src/include/parser/parse_clause.h

index c16aede78c06ef67d5c46bf13bfe74dcea168631..7b6888918bd47a202ef3bdace0a022689f17441b 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.95 2004/01/10 23:28:44 neilc Exp $
+ *       $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.96 2004/01/23 02:13:11 neilc Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -39,6 +39,7 @@
 #include "optimizer/plancat.h"
 #include "optimizer/prep.h"
 #include "parser/gramparse.h"
+#include "parser/parse_clause.h"
 #include "parser/parse_coerce.h"
 #include "parser/parse_expr.h"
 #include "parser/parse_oper.h"
@@ -47,7 +48,6 @@
 #include "utils/acl.h"
 #include "utils/builtins.h"
 #include "utils/fmgroids.h"
-#include "utils/guc.h"
 #include "utils/inval.h"
 #include "utils/lsyscache.h"
 #include "utils/relcache.h"
@@ -189,22 +189,7 @@ DefineRelation(CreateStmt *stmt, char relkind)
        if (parentHasOids)
                descriptor->tdhasoid = true;
        else
-       {
-               switch (stmt->hasoids)
-               {
-                       case MUST_HAVE_OIDS:
-                               descriptor->tdhasoid = true;
-                               break;
-
-                       case MUST_NOT_HAVE_OIDS:
-                               descriptor->tdhasoid = false;
-                               break;
-
-                       case DEFAULT_OIDS:
-                               descriptor->tdhasoid = default_with_oids;
-                               break;
-               }
-       }
+               descriptor->tdhasoid = interpretOidsOption(stmt->hasoids);
 
        if (old_constraints != NIL)
        {
index 8962082134726540583f5dd8b863df082b5b4d8f..75f4f65d78a7644cfe8e3c69d04ef1bfde0ad164 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- *     $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.296 2004/01/14 23:01:55 tgl Exp $
+ *     $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.297 2004/01/23 02:13:12 neilc Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -142,6 +142,7 @@ static void release_pstate_resources(ParseState *pstate);
 static FromExpr *makeFromExpr(List *fromlist, Node *quals);
 static bool check_parameter_resolution_walker(Node *node,
                                                        check_parameter_resolution_context *context);
+static char *makeObjectName(char *name1, char *name2, char *typename);
 
 
 /*
@@ -735,7 +736,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt,
  *     from the truncated characters.  Currently it seems best to keep it simple,
  *     so that the generated names are easily predictable by a person.
  */
-char *
+static char *
 makeObjectName(char *name1, char *name2, char *typename)
 {
        char       *name;
@@ -859,7 +860,6 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt,
        cxt.stmtType = "CREATE TABLE";
        cxt.relation = stmt->relation;
        cxt.inhRelations = stmt->inhRelations;
-       cxt.hasoids = stmt->hasoids;
        cxt.relOid = InvalidOid;
        cxt.columns = NIL;
        cxt.ckconstraints = NIL;
@@ -868,6 +868,7 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt,
        cxt.blist = NIL;
        cxt.alist = NIL;
        cxt.pkey = NULL;
+       cxt.hasoids = interpretOidsOption(stmt->hasoids);
 
        /*
         * Run through each primary element in the table creation clause.
@@ -1979,20 +1980,7 @@ transformSelectStmt(ParseState *pstate, SelectStmt *stmt)
        if (stmt->intoColNames)
                applyColumnNames(qry->targetList, stmt->intoColNames);
 
-       switch (stmt->intoHasOids)
-       {
-               case MUST_HAVE_OIDS:
-                       qry->intoHasOids = true;
-                       break;
-
-               case MUST_NOT_HAVE_OIDS:
-                       qry->intoHasOids = false;
-                       break;
-
-               case DEFAULT_OIDS:
-                       qry->intoHasOids = default_with_oids;
-                       break;
-       }
+       qry->intoHasOids = interpretOidsOption(stmt->intoHasOids);
 
        /* mark column origins */
        markTargetListOrigins(pstate, qry->targetList);
index 8b7be43af13414729dee092f60b738b733bb12bf..6f7a004a6caebf678a8edb9bc630762436853437 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.126 2004/01/14 23:01:55 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.127 2004/01/23 02:13:12 neilc Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -191,7 +191,33 @@ interpretInhOption(InhOption inhOpt)
                case INH_DEFAULT:
                        return SQL_inheritance;
        }
-       elog(ERROR, "bogus InhOption value");
+       elog(ERROR, "bogus InhOption value: %d", inhOpt);
+       return false;                           /* keep compiler quiet */
+}
+
+/*
+ * Given an enum that indicates whether WITH / WITHOUT OIDS was
+ * specified by the user, return true iff the specified table/result
+ * set should be created with OIDs. This needs to be done after
+ * parsing the query string because the return value can depend upon
+ * the default_with_oids GUC var.
+ */
+bool
+interpretOidsOption(ContainsOids opt)
+{
+       switch (opt)
+       {
+               case MUST_HAVE_OIDS:
+                       return true;
+
+               case MUST_NOT_HAVE_OIDS:
+                       return false;
+
+               case DEFAULT_OIDS:
+                       return default_with_oids;
+       }
+
+       elog(ERROR, "bogus ContainsOids value: %d", opt);
        return false;                           /* keep compiler quiet */
 }
 
index 516affd82a0fb1784c099c34d2d45379dbb12a86..e3cf88b4fd76cac1c528afa096b97e282b7b7f42 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/parser/analyze.h,v 1.24 2003/11/29 22:41:09 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/parser/analyze.h,v 1.25 2004/01/23 02:13:12 neilc Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -24,7 +24,4 @@ extern List *analyzeCreateSchemaStmt(CreateSchemaStmt *stmt);
 
 extern void CheckSelectForUpdate(Query *qry);
 
-/* This was exported to allow ADD CONSTRAINT to make use of it */
-extern char *makeObjectName(char *name1, char *name2, char *typename);
-
 #endif   /* ANALYZE_H */
index d91f5e80643ae5af28ec2dd433161f4c698c7c44..fbe1f06c22aadf4a089c2de53ea3a4cbef82075a 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/parser/parse_clause.h,v 1.39 2004/01/14 23:01:55 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/parser/parse_clause.h,v 1.40 2004/01/23 02:13:12 neilc Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -20,6 +20,7 @@ extern void transformFromClause(ParseState *pstate, List *frmList);
 extern int setTargetTable(ParseState *pstate, RangeVar *relation,
                           bool inh, bool alsoSource, AclMode requiredPerms);
 extern bool interpretInhOption(InhOption inhOpt);
+extern bool interpretOidsOption(ContainsOids opt);
 
 extern Node *transformWhereClause(ParseState *pstate, Node *clause,
                                         const char *constructName);