I think I found a bug, or at least a discrepancy. Afaict the
transformSetOperationsStmt function should have identical code to
transformSelectStmt outside of the operations affected by set operations. If
that's the case then the SELECT INTO/CREATE TABLE AS code was not updated when
last it was touched for regular queries.

I think this means WITH[OUT] OIDS and WITH <definition> won't currently work
correctly if the select query involves a UNION or other set operation. Also
temporary tables created with an ON COMMIT option will ignore it and any
tablespace directive will be ignored.

Should I just copy the same code over or is anyone interested in refactoring
this? Or do I have it wrong somehow?

TransformSelectStmt:

        /* handle any SELECT INTO/CREATE TABLE AS spec */
        if (stmt->into)
        {
                qry->into = stmt->into;
                if (stmt->intoColNames)
                        applyColumnNames(qry->targetList, stmt->intoColNames);
                qry->intoOptions = copyObject(stmt->intoOptions);
                qry->intoOnCommit = stmt->intoOnCommit;
                qry->intoTableSpaceName = stmt->intoTableSpaceName;
        }


transformSetOperationStmt:

        /*
         * Handle SELECT INTO/CREATE TABLE AS.
         *
         * Any column names from CREATE TABLE AS need to be attached to both the
         * top level and the leftmost subquery.  We do not do this earlier 
because
         * we do *not* want sortClause processing to be affected.
         */
        if (intoColNames)
        {
                applyColumnNames(qry->targetList, intoColNames);
                applyColumnNames(leftmostQuery->targetList, intoColNames);
        }


-- 
  Gregory Stark
  EnterpriseDB          http://www.enterprisedb.com

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org

Reply via email to