Unix Technical Forum

BUG #2051: CREATE TEMP TABLE AS SELECT doesn't play nice with ON COMMIT DROP

This is a discussion on BUG #2051: CREATE TEMP TABLE AS SELECT doesn't play nice with ON COMMIT DROP within the pgsql Bugs forums, part of the PostgreSQL category; --> The following bug has been logged online: Bug reference: 2051 Logged by: David Fetter Email address: david@fetter.org PostgreSQL version: ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Bugs

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 10:27 AM
David Fetter
 
Posts: n/a
Default BUG #2051: CREATE TEMP TABLE AS SELECT doesn't play nice with ON COMMIT DROP


The following bug has been logged online:

Bug reference: 2051
Logged by: David Fetter
Email address: david@fetter.org
PostgreSQL version: 8.0x
Operating system: Linux
Description: CREATE TEMP TABLE AS SELECT doesn't play nice with ON
COMMIT DROP
Details:

CREATE TEMP TABLE foo
AS SELECT a,b,c
FROM bar
ON COMMIT DROP;

causes a syntax error. So does

CREATE TEMP TABLE foo
ON COMMIT DROP
AS SELECT a,b,c
FROM bar
;

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 10:27 AM
Jaime Casanova
 
Posts: n/a
Default Re: BUG #2051: CREATE TEMP TABLE AS SELECT doesn't play nice with ON COMMIT DROP

On 11/17/05, David Fetter <david@fetter.org> wrote:
>
> The following bug has been logged online:
>
> Bug reference: 2051
> Logged by: David Fetter
> Email address: david@fetter.org
> PostgreSQL version: 8.0x
> Operating system: Linux
> Description: CREATE TEMP TABLE AS SELECT doesn't play nice with ON
> COMMIT DROP
> Details:
>
> CREATE TEMP TABLE foo
> AS SELECT a,b,c
> FROM bar
> ON COMMIT DROP;
>
> causes a syntax error. So does
>
> CREATE TEMP TABLE foo
> ON COMMIT DROP
> AS SELECT a,b,c
> FROM bar
> ;
>


That is because there isn't an ON COMMIT clause for CREATE TABLE AS

see compatibility section in:
http://www.postgresql.org/docs/8.1/s...tetableas.html

--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-10-2008, 10:27 AM
David Fetter
 
Posts: n/a
Default Re: BUG #2051: CREATE TEMP TABLE AS SELECT doesn't play nice with ON COMMIT DROP

On Thu, Nov 17, 2005 at 03:26:21PM -0500, Jaime Casanova wrote:
> On 11/17/05, David Fetter <david@fetter.org> wrote:
> >
> > The following bug has been logged online:
> >
> > Bug reference: 2051
> > Logged by: David Fetter
> > Email address: david@fetter.org
> > PostgreSQL version: 8.0x
> > Operating system: Linux
> > Description: CREATE TEMP TABLE AS SELECT doesn't play nice with ON
> > COMMIT DROP
> > Details:
> >
> > CREATE TEMP TABLE foo
> > AS SELECT a,b,c
> > FROM bar
> > ON COMMIT DROP;
> >
> > causes a syntax error. So does
> >
> > CREATE TEMP TABLE foo
> > ON COMMIT DROP
> > AS SELECT a,b,c
> > FROM bar
> > ;

>
> That is because there isn't an ON COMMIT clause for CREATE TABLE AS
>
> see compatibility section in:
> http://www.postgresql.org/docs/8.1/s...tetableas.html


This is still a bug, or at least a big gotcha.

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100 mobile: +1 415 235 3778

Remember to vote!

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-10-2008, 10:28 AM
Tom Lane
 
Posts: n/a
Default Re: BUG #2051: CREATE TEMP TABLE AS SELECT doesn't play nice with ON COMMIT DROP

David Fetter <david@fetter.org> writes:
> This is still a bug,


No, it's a feature request, and a rather low-priority one considering
you can already do

CREATE TEMP TABLE foo ... ON COMMIT DROP;
INSERT INTO foo SELECT ...

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-10-2008, 10:28 AM
David Fetter
 
Posts: n/a
Default Re: BUG #2051: CREATE TEMP TABLE AS SELECT doesn't play nice with ON COMMIT DROP

On Thu, Nov 17, 2005 at 04:37:14PM -0500, Tom Lane wrote:
> David Fetter <david@fetter.org> writes:
> > This is still a bug,

>
> No, it's a feature request, and a rather low-priority one considering
> you can already do
>
> CREATE TEMP TABLE foo ... ON COMMIT DROP;


It's that first little elipsis mark that's the problem. Is there
something really clever I've been missing on how to do a dynamic table
creation?

CREATE TABLE foo (LIKE SELECT ...);

or some such?

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100 mobile: +1 415 235 3778

Remember to vote!

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-10-2008, 10:28 AM
Tom Lane
 
Posts: n/a
Default Re: BUG #2051: CREATE TEMP TABLE AS SELECT doesn't play nice with ON COMMIT DROP

David Fetter <david@fetter.org> writes:
> On Thu, Nov 17, 2005 at 04:37:14PM -0500, Tom Lane wrote:
>> CREATE TEMP TABLE foo ... ON COMMIT DROP;


> It's that first little elipsis mark that's the problem. Is there
> something really clever I've been missing on how to do a dynamic table
> creation?


Oh, you're worried about what to do if you don't know the output column
set of the query? OK, that is a bit harder, but I think it's still a
corner case. How much are you really going to get done with the table
if you don't know what columns it has?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-10-2008, 10:28 AM
David Fetter
 
Posts: n/a
Default Re: BUG #2051: CREATE TEMP TABLE AS SELECT doesn't play nice with ON COMMIT DROP

On Thu, Nov 17, 2005 at 05:32:43PM -0500, Tom Lane wrote:
> David Fetter <david@fetter.org> writes:
> > On Thu, Nov 17, 2005 at 04:37:14PM -0500, Tom Lane wrote:
> >> CREATE TEMP TABLE foo ... ON COMMIT DROP;

>
> > It's that first little elipsis mark that's the problem. Is there
> > something really clever I've been missing on how to do a dynamic
> > table creation?

>
> Oh, you're worried about what to do if you don't know the output
> column set of the query? OK, that is a bit harder, but I think it's
> still a corner case. How much are you really going to get done with
> the table if you don't know what columns it has?


My use case is when I have a system of audit tables that look like
this:

CREATE TABLE foo (
...
);

CREATE TABLE foo_audit (
foo_audit_id BIGSERIAL PRIMARY KEY,
foo_actor TEXT,
foo_timestamp TIMESTAMP,
foo_action char(1) CHECK foo_action IN('D','I','U'),
old_foo foo,
new_foo foo
);

with appropriate TRIGGERs, etc. to make that happen. It nice feature
of being partitionable via constraint exclusion.

This is in aid of a system for making it possible to ALTER foo while
preserving the data in foo_audit.

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100 mobile: +1 415 235 3778

Remember to vote!

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-10-2008, 10:28 AM
Neil Conway
 
Posts: n/a
Default Re: BUG #2051: CREATE TEMP TABLE AS SELECT doesn't play

On Thu, 2005-11-17 at 13:07 -0800, David Fetter wrote:
> This is still a bug, or at least a big gotcha.


It's not a bug, merely an unimplemented feature. If no one beats me to
it I'll take a look at doing this for 8.2.

-Neil



---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-10-2008, 10:28 AM
David Fetter
 
Posts: n/a
Default Re: BUG #2051: CREATE TEMP TABLE AS SELECT doesn't play

On Thu, Nov 17, 2005 at 07:11:42PM -0500, Neil Conway wrote:
> On Thu, 2005-11-17 at 13:07 -0800, David Fetter wrote:
> > This is still a bug, or at least a big gotcha.

>
> It's not a bug, merely an unimplemented feature. If no one beats me
> to it I'll take a look at doing this for 8.2.


Fantastic

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100 mobile: +1 415 235 3778

Remember to vote!

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-10-2008, 10:29 AM
Bruce Momjian
 
Posts: n/a
Default Re: BUG #2051: CREATE TEMP TABLE AS SELECT doesn't play nice


TODO has:

o Add ON COMMIT capability to CREATE TABLE AS ... SELECT

---------------------------------------------------------------------------

David Fetter wrote:
> On Thu, Nov 17, 2005 at 05:32:43PM -0500, Tom Lane wrote:
> > David Fetter <david@fetter.org> writes:
> > > On Thu, Nov 17, 2005 at 04:37:14PM -0500, Tom Lane wrote:
> > >> CREATE TEMP TABLE foo ... ON COMMIT DROP;

> >
> > > It's that first little elipsis mark that's the problem. Is there
> > > something really clever I've been missing on how to do a dynamic
> > > table creation?

> >
> > Oh, you're worried about what to do if you don't know the output
> > column set of the query? OK, that is a bit harder, but I think it's
> > still a corner case. How much are you really going to get done with
> > the table if you don't know what columns it has?

>
> My use case is when I have a system of audit tables that look like
> this:
>
> CREATE TABLE foo (
> ...
> );
>
> CREATE TABLE foo_audit (
> foo_audit_id BIGSERIAL PRIMARY KEY,
> foo_actor TEXT,
> foo_timestamp TIMESTAMP,
> foo_action char(1) CHECK foo_action IN('D','I','U'),
> old_foo foo,
> new_foo foo
> );
>
> with appropriate TRIGGERs, etc. to make that happen. It nice feature
> of being partitionable via constraint exclusion.
>
> This is in aid of a system for making it possible to ALTER foo while
> preserving the data in foo_audit.
>
> Cheers,
> D
> --
> David Fetter david@fetter.org http://fetter.org/
> phone: +1 510 893 6100 mobile: +1 415 235 3778
>
> Remember to vote!
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>


--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

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

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:14 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com