X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id A2749474E4F for ; Fri, 14 Feb 2003 13:41:10 -0500 (EST) Received: from biglumber.com (biglumber.com [207.228.252.42]) by postgresql.org (Postfix) with SMTP id F2D10474E42 for ; Fri, 14 Feb 2003 13:41:09 -0500 (EST) Received: (qmail 13445 invoked from network); 14 Feb 2003 18:41:10 -0000 Received: from biglumber.com (HELO localhost) (207.228.252.42) by 0 with SMTP; 14 Feb 2003 18:41:10 -0000 From: greg@turnstep.com To: pgsql-sql@postgresql.org Subject: Re: Drop temporary table only if it exists X-PGP-Key: 2529 DF6A B8F7 9407 E944 45B4 BC9B 9067 1496 4AC8 In-Reply-To: <200302140948.15889.josh@agliodbs.com> Date: Fri, 14 Feb 2003 18:41:10 -0000 X-Mailer: JoyMail 1.36 Message-ID: <784d32a2b3c0b617ad1f80c9d9c6f002@biglumber.com> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/343 X-Sequence-Number: 11741 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 > A quick check for existance: > > SELECT * FROM pg_class WHERE relname = 'name_of_temp_table' and relkind = ? > > You'll want to look in the docs about the PG system tables to see what > "relkind" you should test on for each type of object. If you are using 7.3, you also need to to consider the namespace: temporary relations live in their own schema. To find out if the temporary table (relkind='r') named "neptune" exists: SELECT COUNT(*) FROM pg_class WHERE LOWER(relname) = 'neptune' AND relkind = 'r' AND relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname ~ '^pg_temp'); To find out about a sequence (relkind='S') named "saturn" exists: SELECT COUNT(*) FROM pg_class WHERE LOWER(relname) = 'saturn' AND relkind = 'S' AND relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname ~ '^pg_temp'); To find out if "jupiter" is used by any temp relations: SELECT COUNT(*) FROM pg_class WHERE LOWER(relname) = 'jupiter' AND relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname ~ '^pg_temp'); To use the above on a pre-7.3 system, just remove the last line that mentions relnamespace. - -- Greg Sabino Mullane greg@turnstep.com PGP Key: 0x14964AC8 200302141327 -----BEGIN PGP SIGNATURE----- Comment: http://www.turnstep.com/pgp.html iD8DBQE+TTdmvJuQZxSWSsgRAtVNAKDtWkTxxg++vqJ7asqMG54BDCzPiQCg3dBG SbKhIdttHz4fVV1SMeyGqXE= =+JMB -----END PGP SIGNATURE-----