pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Possible Bug regarding temp tables (sql or psql?)
11+ messages / 4 participants
[nested] [flat]

* Possible Bug regarding temp tables (sql or psql?)
@ 2002-07-03 20:59  Mark Frazer <mark@somanetworks.com>
  0 siblings, 1 reply; 11+ messages in thread

From: Mark Frazer @ 2002-07-03 20:59 UTC (permalink / raw)
  To: pgsql-sql@postgresql.org; pgsql-interfaces@somanetworks.com

When using the attached script in psql, the temp variables disappear as 
far as \distv shows, but running the script a second time fails.

To reproduce, save the following script as bug.sql, then start psql on an
test database.
\i bug.sql
\distv
-- no relations should be shown
\i bug.sql 
-- this will fail.

However, if you run psql again, you can
\i bug.sql
successfully.  It will only fail if run twice in the same script.

cheers
-mark

-- 
Hardy Boys: too easy. Nancy Drew: too hard! - Fry

Attachments:

bug.sql (text/plain, 536B) download CREATE TABLE foo ( foo_idx SERIAL PRIMARY KEY, foo INTEGER ) ; CREATE TABLE bar ( bar_idx SERIAL PRIMARY KEY, foo_idx INTEGER REFERENCES foo, bar INTEGER ) ; INSERT INTO foo ( foo ) VALUES ( 111 ) ; INSERT INTO foo ( foo ) VALUES ( 222 ) ; INSERT INTO foo ( foo ) VALUES ( 333 ) ; BEGIN WORK ; SELECT foo_idx INTO TEMP v_idx FROM foo WHERE foo.foo = 222 ; INSERT INTO bar ( foo_idx, bar ) VALUES ( v_idx.foo_idx, 888 ) ; END WORK ; DROP TABLE foo ; DROP SEQUENCE foo_foo_idx_seq ; DROP TABLE bar ; DROP SEQUENCE bar_bar_idx_seq ;
^ permalink raw reply [nested|flat] 11+ messages in thread

* Re: Possible Bug regarding temp tables (sql or psql?)
@ 2002-07-03 21:12  Mark Frazer <mark@somanetworks.com>
  parent: Mark Frazer <mark@somanetworks.com>
  0 siblings, 1 reply; 11+ messages in thread

From: Mark Frazer @ 2002-07-03 21:12 UTC (permalink / raw)
  To: pgsql-sql@postgresql.org; pgsql-interfaces

Forgot to mention that adding
DROP TABLE v_idx ;
before the END WORK will fix things.  However, I was under the impression that
temporary tables would go away after a transaction in which they were created
was committed.






^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Possible Bug regarding temp tables (sql or psql?)
@ 2002-07-04 01:38  Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  parent: Mark Frazer <mark@somanetworks.com>
  0 siblings, 1 reply; 11+ messages in thread

From: Christopher Kings-Lynne @ 2002-07-04 01:38 UTC (permalink / raw)
  To: Mark Frazer <mark@somanetworks.com>; pgsql-sql@postgresql.org

> Forgot to mention that adding
> DROP TABLE v_idx ;
> before the END WORK will fix things.  However, I was under the
> impression that
> temporary tables would go away after a transaction in which they
> were created
> was committed.

No - they go away at the end of a _connection_.  However, there is now a
patch floating around on -hackers that would add an ' ON COMMIT DROP;'
option to CREATE TEMP TABLE.

Chris






^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: [SQL] Possible Bug regarding temp tables (sql or psql?)
@ 2002-07-04 11:23  Mark Frazer <mark@somanetworks.com>
  parent: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  0 siblings, 2 replies; 11+ messages in thread

From: Mark Frazer @ 2002-07-04 11:23 UTC (permalink / raw)
  To: pgsql-sql@postgresql.org; +Cc: pgsql-interfaces

Any idea why the table can't be seen with \d in psql then?

Christopher Kings-Lynne <chriskl@familyhealth.com.au> [02/07/04 00:21]:
> 
> No - they go away at the end of a _connection_.  However, there is now a
> patch floating around on -hackers that would add an ' ON COMMIT DROP;'
> option to CREATE TEMP TABLE.

-- 
In the event of an emergency, my ass can be used as a flotation
device. - Bender





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: [SQL] Possible Bug regarding temp tables (sql or psql?)
@ 2002-07-04 12:26  Bruce Momjian <pgman@candle.pha.pa.us>
  parent: Mark Frazer <mark@somanetworks.com>
  1 sibling, 0 replies; 11+ messages in thread

From: Bruce Momjian @ 2002-07-04 12:26 UTC (permalink / raw)
  To: Mark Frazer <mark@somanetworks.com>; +Cc: pgsql-sql@postgresql.org; pgsql-interfaces

Mark Frazer wrote:
> Any idea why the table can't be seen with \d in psql then?

It is a known problem with temp tables.  They aren't visible with \d
because they are invisible system tables that are removed on exit.  I
think 7.3 will fix this.

> 
> Christopher Kings-Lynne <chriskl@familyhealth.com.au> [02/07/04 00:21]:
> > 
> > No - they go away at the end of a _connection_.  However, there is now a
> > patch floating around on -hackers that would add an ' ON COMMIT DROP;'
> > option to CREATE TEMP TABLE.
> 
> -- 
> In the event of an emergency, my ass can be used as a flotation
> device. - Bender
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: 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
> 
> 
> 

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Possible Bug regarding temp tables (sql or psql?)
@ 2002-07-05 02:02  Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  parent: Mark Frazer <mark@somanetworks.com>
  1 sibling, 1 reply; 11+ messages in thread

From: Christopher Kings-Lynne @ 2002-07-05 02:02 UTC (permalink / raw)
  To: Mark Frazer <mark@somanetworks.com>; pgsql-sql@postgresql.org

IIRC they are only visible in the connection that created them?  Am I right?
Either way, I don't think \d will show them - there might be another
command...

Chris

> Any idea why the table can't be seen with \d in psql then?
>
> Christopher Kings-Lynne <chriskl@familyhealth.com.au> [02/07/04 00:21]:
> >
> > No - they go away at the end of a _connection_.  However, there is now a
> > patch floating around on -hackers that would add an ' ON COMMIT DROP;'
> > option to CREATE TEMP TABLE.






^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Possible Bug regarding temp tables (sql or psql?)
@ 2002-07-05 02:09  Bruce Momjian <pgman@candle.pha.pa.us>
  parent: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  0 siblings, 2 replies; 11+ messages in thread

From: Bruce Momjian @ 2002-07-05 02:09 UTC (permalink / raw)
  To: Christopher Kings-Lynne <chriskl@familyhealth.com.au>; +Cc: Mark Frazer <mark@somanetworks.com>; pgsql-sql@postgresql.org

Christopher Kings-Lynne wrote:
> IIRC they are only visible in the connection that created them?  Am I right?
> Either way, I don't think \d will show them - there might be another
> command...
> 

TODO has:

	* Allow psql \d to show temporary table structure

Looks like it works fine now with schemas:
	
	test=> create temp table xx(x int);
	CREATE TABLE
	test=> \d
	    List of relations
	 Name | Type  |  Owner   
	------+-------+----------
	 x    | table | postgres
	 xx   | table | postgres
	(2 rows)

I will mark the TODO as done.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Possible Bug regarding temp tables (sql or psql?)
@ 2002-07-05 02:32  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Bruce Momjian <pgman@candle.pha.pa.us>
  1 sibling, 1 reply; 11+ messages in thread

From: Tom Lane @ 2002-07-05 02:32 UTC (permalink / raw)
  To: Bruce Momjian <pgman@candle.pha.pa.us>; +Cc: Christopher Kings-Lynne <chriskl@familyhealth.com.au>; Mark Frazer <mark@somanetworks.com>; pgsql-sql@postgresql.org

Bruce Momjian <pgman@candle.pha.pa.us> writes:
> TODO has:
> 	* Allow psql \d to show temporary table structure
> Looks like it works fine now with schemas:

More accurately, it's no more broken for temp tables than any other
tables at the moment.

regression=# create table foo (f1 int);
CREATE TABLE
regression=# create temp table foo (f1 text, f2 float);
CREATE TABLE
regression=# \d foo
              Table "foo"
 Column |       Type       | Modifiers
--------+------------------+-----------
 f1     | integer          |
 f1     | text             |
 f2     | double precision |

regression=#

Even uglier cases occur if some other connection has also created
a temp table named foo.  You should *not* see that in \d ... but
you will.

> I will mark the TODO as done.

It's not really done, but the remaining fixes will fall out of making
psql schema-aware.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Possible Bug regarding temp tables (sql or psql?)
@ 2002-07-05 02:39  Bruce Momjian <pgman@candle.pha.pa.us>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 11+ messages in thread

From: Bruce Momjian @ 2002-07-05 02:39 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Christopher Kings-Lynne <chriskl@familyhealth.com.au>; Mark Frazer <mark@somanetworks.com>; pgsql-sql@postgresql.org

Tom Lane wrote:
> Even uglier cases occur if some other connection has also created
> a temp table named foo.  You should *not* see that in \d ... but
> you will.
> 
> > I will mark the TODO as done.
> 
> It's not really done, but the remaining fixes will fall out of making
> psql schema-aware.

The original bug is gone.  We just have new ones.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Possible Bug regarding temp tables (sql or psql?)
@ 2002-07-05 13:38  Mark Frazer <mark@somanetworks.com>
  parent: Bruce Momjian <pgman@candle.pha.pa.us>
  1 sibling, 1 reply; 11+ messages in thread

From: Mark Frazer @ 2002-07-05 13:38 UTC (permalink / raw)
  To: Bruce Momjian <pgman@candle.pha.pa.us>; +Cc: Christopher Kings-Lynne <chriskl@familyhealth.com.au>; pgsql-sql@postgresql.org



Bruce Momjian <pgman@candle.pha.pa.us> [02/07/04 22:10]:
> 
> TODO has:
> 
> 	* Allow psql \d to show temporary table structure
> 
> Looks like it works fine now with schemas:
> 	
> I will mark the TODO as done.

It doesn't work with select into though:

config=> select 5 into temp v_tmp ;
SELECT
config=> \d v_tmp 
Did not find any relation named "v_tmp".
config=> select 4 into temp v_tmp ;
ERROR:  Relation 'v_tmp' already exists
config=> select version() ;
                           version                           
-------------------------------------------------------------
 PostgreSQL 7.2.1 on i686-pc-linux-gnu, compiled by GCC 2.96


-- 
I heard one time you single-handedly defeated a hoard of rampaging somethings
in the something something system. - Fry





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Possible Bug regarding temp tables (sql or psql?)
@ 2002-07-05 18:52  Bruce Momjian <pgman@candle.pha.pa.us>
  parent: Mark Frazer <mark@somanetworks.com>
  0 siblings, 0 replies; 11+ messages in thread

From: Bruce Momjian @ 2002-07-05 18:52 UTC (permalink / raw)
  To: Mark Frazer <mark@somanetworks.com>; +Cc: Christopher Kings-Lynne <chriskl@familyhealth.com.au>; pgsql-sql@postgresql.org


It works, but only in CVS, not in 7.2.X.  Marking something as done in
TODO only means it is done and will be in the _next_ release.  Sorry.

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

Mark Frazer wrote:
> 
> 
> Bruce Momjian <pgman@candle.pha.pa.us> [02/07/04 22:10]:
> > 
> > TODO has:
> > 
> > 	* Allow psql \d to show temporary table structure
> > 
> > Looks like it works fine now with schemas:
> > 	
> > I will mark the TODO as done.
> 
> It doesn't work with select into though:
> 
> config=> select 5 into temp v_tmp ;
> SELECT
> config=> \d v_tmp 
> Did not find any relation named "v_tmp".
> config=> select 4 into temp v_tmp ;
> ERROR:  Relation 'v_tmp' already exists
> config=> select version() ;
>                            version                           
> -------------------------------------------------------------
>  PostgreSQL 7.2.1 on i686-pc-linux-gnu, compiled by GCC 2.96
> 
> 
> -- 
> I heard one time you single-handedly defeated a hoard of rampaging somethings
> in the something something system. - Fry
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
> 
> 
> 

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026





^ permalink  raw  reply  [nested|flat] 11+ messages in thread


end of thread, other threads:[~2002-07-05 18:52 UTC | newest]

Thread overview: 11+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-07-03 20:59 Possible Bug regarding temp tables (sql or psql?) Mark Frazer <mark@somanetworks.com>
2002-07-03 21:12 ` Mark Frazer <mark@somanetworks.com>
2002-07-04 01:38   ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2002-07-04 11:23     ` Mark Frazer <mark@somanetworks.com>
2002-07-04 12:26       ` Bruce Momjian <pgman@candle.pha.pa.us>
2002-07-05 02:02       ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2002-07-05 02:09         ` Bruce Momjian <pgman@candle.pha.pa.us>
2002-07-05 02:32           ` Tom Lane <tgl@sss.pgh.pa.us>
2002-07-05 02:39             ` Bruce Momjian <pgman@candle.pha.pa.us>
2002-07-05 13:38           ` Mark Frazer <mark@somanetworks.com>
2002-07-05 18:52             ` Bruce Momjian <pgman@candle.pha.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox