Re: [SQL] temp table existence

2007-12-30 Thread Pavel Stehule
Hello On 30/12/2007, Erik Jones [EMAIL PROTECTED] wrote: On Dec 29, 2007, at 3:16 PM, Marcin Krawczyk wrote: I just realized something... my bad. It will work since TRUNCATE removes only table from current session. If the table exists and you're going to TRUNCATE it before using it, you

[SQL] temp table existence

2007-12-29 Thread Marcin Krawczyk
Hi all. Is there a way to determine the existence of a TEMP TABLE? I need to check i it exists before I create it. Doing simple check on pg_class or pg_tables is not enough because there may be other such tables created in other sessions. Or maybe anyone knows the identification (apart from

Re: [SQL] temp table existence

2007-12-29 Thread Pavel Stehule
Hello On 29/12/2007, Marcin Krawczyk [EMAIL PROTECTED] wrote: Hi all. Is there a way to determine the existence of a TEMP TABLE? I need to check i it exists before I create it. Doing simple check on pg_class or pg_tables is not enough because there may be other such tables created in other

Re: [SQL] temp table existence

2007-12-29 Thread Marcin Krawczyk
Thanks for the answer but it's not quite sufficient. The code supplied on his page: CREATE OR REPLACE FUNCTION ... BEGIN PERFORM 1 FROM pg_catalog.pg_tables WHERE tablename = 'xx' AND schemaname LIKE 'pg_temp%'; IF FOUND THEN TRUNCATE xx; ELSE CREATE TEMP TABLE xx(... END IF; The function does

Re: [SQL] temp table existence

2007-12-29 Thread Marcin Krawczyk
I just realized something... my bad. It will work since TRUNCATE removes only table from current session. Thank you again. Regards

Re: [SQL] temp table existence

2007-12-29 Thread Pavel Stehule
Hello my solution isn't 100% perfect too. Better is test visibility: SELECT n.nspname as Schema, c.relname as Name, CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' END as Type, r.rolname as Owner FROM

Re: [SQL] temp table existence

2007-12-29 Thread Adrian Klaver
- Original message -- From: Marcin Krawczyk [EMAIL PROTECTED] Hi all. Is there a way to determine the existence of a TEMP TABLE? I need to check i it exists before I create it. Doing simple check on pg_class or pg_tables is not enough because there may be other

Re: [SQL] temp table existence

2007-12-29 Thread Erik Jones
On Dec 29, 2007, at 3:16 PM, Marcin Krawczyk wrote: I just realized something... my bad. It will work since TRUNCATE removes only table from current session. If the table exists and you're going to TRUNCATE it before using it, you could just use DROP TABLE IF EXISTS and then create it. I