Re: create temp table .. on commit delete rows

Lists: pgsql-hackers
From: Teodor Sigaev <teodor(at)sigaev(dot)ru>
To: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: create temp table .. on commit delete rows
Date: 2006-10-12 11:34:29
Message-ID: 452E2845.6040901@sigaev.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

1)
# create temp table a ( a int ) without oids on commit delete rows;
# insert into a values(1);
# begin;
# insert into a values(2);
# commit;
# select * from a;
a
---
(0 rows)

2)
# insert into a values(1);
# begin;
# insert into a values(2);
# rollback;
# select * from a;
a
---
(0 rows)

It seems to me that 1) is good, but 2) makes some strange, unpredictable result...

--
Teodor Sigaev E-mail: teodor(at)sigaev(dot)ru
WWW: http://www.sigaev.ru/


From: Heikki Linnakangas <heikki(at)enterprisedb(dot)com>
To: Teodor Sigaev <teodor(at)sigaev(dot)ru>
Cc: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: create temp table .. on commit delete rows
Date: 2006-10-12 11:44:12
Message-ID: 452E2A8C.6060601@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Teodor Sigaev wrote:
> 2)
> # insert into a values(1);

You're running in auto-commit, mode. An implicit commit happens after
this statement. Which clears the table.

> # begin;
> # insert into a values(2);
> # rollback;
> # select * from a;
> a
> ---
> (0 rows)
>
> It seems to me that 1) is good, but 2) makes some strange, unpredictable
> result...

Looks right to me.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com


From: Teodor Sigaev <teodor(at)sigaev(dot)ru>
To: Heikki Linnakangas <heikki(at)enterprisedb(dot)com>
Cc: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: create temp table .. on commit delete rows
Date: 2006-10-12 11:51:39
Message-ID: 452E2C4B.7010607@sigaev.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> You're running in auto-commit, mode. An implicit commit happens after
> this statement. Which clears the table.
> Looks right to me.

Oops, I see

--
Teodor Sigaev E-mail: teodor(at)sigaev(dot)ru
WWW: http://www.sigaev.ru/


From: David Fetter <david(at)fetter(dot)org>
To: Teodor Sigaev <teodor(at)sigaev(dot)ru>
Cc: Heikki Linnakangas <heikki(at)enterprisedb(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: create temp table .. on commit delete rows
Date: 2006-10-12 19:01:12
Message-ID: 20061012190112.GD24237@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Oct 12, 2006 at 03:51:39PM +0400, Teodor Sigaev wrote:
> >You're running in auto-commit, mode. An implicit commit happens
> >after this statement. Which clears the table. Looks right to me.
>
> Oops, I see

Should something notice and raise a warning when people create a TEMP
table and have AUTOCOMMIT on?

Cheers,
D
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
phone: +1 415 235 3778 AIM: dfetter666
Skype: davidfetter

Remember to vote!


From: "Jim C(dot) Nasby" <jim(at)nasby(dot)net>
To: David Fetter <david(at)fetter(dot)org>
Cc: Teodor Sigaev <teodor(at)sigaev(dot)ru>, Heikki Linnakangas <heikki(at)enterprisedb(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: create temp table .. on commit delete rows
Date: 2006-10-12 19:07:28
Message-ID: 20061012190728.GS28647@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Oct 12, 2006 at 12:01:12PM -0700, David Fetter wrote:
> On Thu, Oct 12, 2006 at 03:51:39PM +0400, Teodor Sigaev wrote:
> > >You're running in auto-commit, mode. An implicit commit happens
> > >after this statement. Which clears the table. Looks right to me.
> >
> > Oops, I see
>
> Should something notice and raise a warning when people create a TEMP
> table and have AUTOCOMMIT on?

Maybe if ON COMMIT is set to DELETE ROWS or DROP...
--
Jim Nasby jim(at)nasby(dot)net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)


From: David Fetter <david(at)fetter(dot)org>
To: "Jim C(dot) Nasby" <jim(at)nasby(dot)net>
Cc: Teodor Sigaev <teodor(at)sigaev(dot)ru>, Heikki Linnakangas <heikki(at)enterprisedb(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: create temp table .. on commit delete rows
Date: 2006-10-12 19:48:25
Message-ID: 20061012194825.GE24237@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Oct 12, 2006 at 02:07:28PM -0500, Jim C. Nasby wrote:
> On Thu, Oct 12, 2006 at 12:01:12PM -0700, David Fetter wrote:
> > On Thu, Oct 12, 2006 at 03:51:39PM +0400, Teodor Sigaev wrote:
> > > >You're running in auto-commit, mode. An implicit commit
> > > >happens after this statement. Which clears the table. Looks
> > > >right to me.
> > >
> > > Oops, I see
> >
> > Should something notice and raise a warning when people create a
> > TEMP table and have AUTOCOMMIT on?
>
> Maybe if ON COMMIT is set to DELETE ROWS or DROP...

Sounds good :)

Cheers,
D
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
phone: +1 415 235 3778 AIM: dfetter666
Skype: davidfetter

Remember to vote!


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: David Fetter <david(at)fetter(dot)org>
Cc: "Jim C(dot) Nasby" <jim(at)nasby(dot)net>, Teodor Sigaev <teodor(at)sigaev(dot)ru>, Heikki Linnakangas <heikki(at)enterprisedb(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: create temp table .. on commit delete rows
Date: 2006-10-12 21:29:15
Message-ID: 200610122129.k9CLTF605498@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

David Fetter wrote:
> On Thu, Oct 12, 2006 at 02:07:28PM -0500, Jim C. Nasby wrote:
> > On Thu, Oct 12, 2006 at 12:01:12PM -0700, David Fetter wrote:
> > > On Thu, Oct 12, 2006 at 03:51:39PM +0400, Teodor Sigaev wrote:
> > > > >You're running in auto-commit, mode. An implicit commit
> > > > >happens after this statement. Which clears the table. Looks
> > > > >right to me.
> > > >
> > > > Oops, I see
> > >
> > > Should something notice and raise a warning when people create a
> > > TEMP table and have AUTOCOMMIT on?
> >
> > Maybe if ON COMMIT is set to DELETE ROWS or DROP...
>
> Sounds good :)

Added to TODO:

o Issue a notice if CREATE TABLE ... ON COMMIT { DELETE ROWS |
DROP } is issued outside a multi-statement transaction

--
Bruce Momjian bruce(at)momjian(dot)us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: David Fetter <david(at)fetter(dot)org>, "Jim C(dot) Nasby" <jim(at)nasby(dot)net>, Teodor Sigaev <teodor(at)sigaev(dot)ru>, Heikki Linnakangas <heikki(at)enterprisedb(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: create temp table .. on commit delete rows
Date: 2006-10-12 22:17:35
Message-ID: 20078.1160691455@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> David Fetter wrote:
>>> Should something notice and raise a warning when people create a
>>> TEMP table and have AUTOCOMMIT on?

> Added to TODO:
> o Issue a notice if CREATE TABLE ... ON COMMIT { DELETE ROWS |
> DROP } is issued outside a multi-statement transaction

That is *not* what was suggested, and it doesn't seem very useful. The
problem really comes when one uses a temp table in autocommit mode, not
at creation time.

The problem with the original suggestion is that the backend can't do it
because AUTOCOMMIT is a notion that exists only in the client-side code.
And the client can't do it very well because it'd have to parse SQL
commands, and even with that it wouldn't see CREATE TEMP TABLE commands
issued inside functions.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: David Fetter <david(at)fetter(dot)org>, "Jim C(dot) Nasby" <jim(at)nasby(dot)net>, Teodor Sigaev <teodor(at)sigaev(dot)ru>, Heikki Linnakangas <heikki(at)enterprisedb(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: create temp table .. on commit delete rows
Date: 2006-10-12 22:32:50
Message-ID: 200610122232.k9CMWo522955@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > David Fetter wrote:
> >>> Should something notice and raise a warning when people create a
> >>> TEMP table and have AUTOCOMMIT on?
>
> > Added to TODO:
> > o Issue a notice if CREATE TABLE ... ON COMMIT { DELETE ROWS |
> > DROP } is issued outside a multi-statement transaction
>
> That is *not* what was suggested, and it doesn't seem very useful. The
> problem really comes when one uses a temp table in autocommit mode, not
> at creation time.
>
> The problem with the original suggestion is that the backend can't do it
> because AUTOCOMMIT is a notion that exists only in the client-side code.
> And the client can't do it very well because it'd have to parse SQL
> commands, and even with that it wouldn't see CREATE TEMP TABLE commands
> issued inside functions.

Ewe. Yea, I will just remove it. We can't issue a warning easily.

--
Bruce Momjian bruce(at)momjian(dot)us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +