Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"IF EXIST" equivalent sought!

Status
Not open for further replies.

boolean

Programmer
Mar 5, 2002
35
US
Greetings,

I need to drop a couple of tables from the dictionary, and I know that I need to use:

DROP TABLE <TABLENAME> IN DICTIONARY

but then, I need to drop the table only if it exists.

Essentially I am making a .SQL file that would be run using the PSQL ODBC driver, and if the above statement is run for non-existing tables, an error is bombed.
So I would like to execute the SQL query conditionally.
I know that I can do this using a simple 'IF EXISTS' condition in Microsoft SQL, but the equivalent doesnt seem to be available with PSQL.

I did unearth the:

SELECT * FROM Person p WHERE EXISTS
(SELECT * FROM Enrolls e WHERE e.Student_ID = p.id
AND Grade = 4.0)

example in the documentation, but the;

DROP TABLE <TABLENAME> IN DICTIONARY WHERE EXISTS (select * from X$file where xf$name = '<TABLENAME>')

will not work as the DROP statement doesnt support this.

I am essentially looking for a work around.

Thanks for the help thats on its way
SHAMmmmm...
 
If you use a stored procedure, you should be able to do this:

DECLARE :TestName char(20);
SELECT XF$Name INTO :TestName FROM X$File WHERE XF$Name='<Tablename>'
IF RTrim:)TestName) = '<TableName>' THEN
DROP TABLE <TableName>
End If

... rest of create ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top