Skip site navigation (1) Skip section navigation (2)

Re: add additional options to CREATE TABLE ... AS

From: Neil Conway <neilc(at)samurai(dot)com>
To: Kris Jurka <books(at)ejurka(dot)com>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: add additional options to CREATE TABLE ... AS
Date: 2006-02-14 20:27:12
Message-ID: 1139948832.31672.15.camel@localhost.localdomain (view raw, whole thread or download thread mbox)
Lists: pgsql-patches
On Tue, 2006-02-14 at 14:32 -0500, Kris Jurka wrote:
> This patch adds most of the options available for regular CREATE TABLE 
> syntax to the CREATE TABLE x AS SELECT ... and AS EXECUTE ... 
> Specifically this allows specification of on commit behavior for temp 
> tables and tablespaces for regular tables to these two statements.

The implementation is pretty ugly -- it clutters ExecuteStmt and Query
with fields that really do not belong there. Per previous discussion, I
think it would be better to refactor the CREATE TABLE AS implementation
to be essentially a CREATE TABLE followed by a INSERT ... SELECT.

(That's not necessarily a reason to reject the patch, but the patch does
increase the benefit of performing that refactoring.)

A few cosmetic comments:

typedef struct ExecuteStmt
	NodeTag			type;
	char		   *name;
	RangeVar	   *into;
	ContainsOids	intocontainsoids;
	bool			intohasoids;
	OnCommitAction	intooncommit;
	char		   *intotablespacename;
	List		   *params;
} ExecuteStmt;

I think we ought to use either camel-case or underscore characters to
separate words.

parser/analyze.c, circa 1822:

    if (stmt->intoTableSpaceName)
        qry->intoTableSpaceName = pstrdup(stmt->intoTableSpaceName);
        qry->intoTableSpaceName = NULL;

You can omit the "else", as makeNode() zeroes all the fields of the new
node. (You could argue that leaving the assignment is more readable, but
I personally don't think so: this behavior of makeNode() is used in a
several places in the backend.)


In response to


pgsql-patches by date

Next:From: Tom LaneDate: 2006-02-14 20:38:48
Subject: Re: add additional options to CREATE TABLE ... AS
Previous:From: Andrew KlostermanDate: 2006-02-14 20:25:06
Subject: Re: BUG #2246: Bad malloc interactions: ecpg, openssl

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group