Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create ot replace table

Tags:

teradata

Is there any way in teradata to

CREATE OR REPLACE VOLATILE TABLE 
AS
(
SELECT 

)

I need to make sure that it does not stop if the table already exists

like image 293
Aleksei Nikolaevich Avatar asked Jun 13 '26 09:06

Aleksei Nikolaevich


2 Answers

As a Volatile Table is only visible within the current session you should know which tables have been created.

Otherwise i would simply try a DROP TABLE first and ignore a possible "object does not exist" error.

like image 92
dnoeth Avatar answered Jun 15 '26 22:06

dnoeth


Short answer: No. Volatile table definitions are not stored in the data dictionary table DBC.Tables. Unlike a Global Temporary table the instantiation of a volatile table is also not tracked by a dictionary table in DBC.TempTables.

Longer answer: You can but it depends on where your SQL is executing.

You can check simply check for the existence of the table using something like SELECT 1 FROM {VolatileTableName} WHERE 1=0; or SELECT 'X' FROM {VolatileTableName] GROUP BY 1; and trap the error if the object doesn't exist. If you don't get an error the object exists. Without knowing where your code is running (BTEQ, Stored Procedure, Macro) it is difficult to explain the appropriate error handling.

like image 22
Rob Paller Avatar answered Jun 15 '26 22:06

Rob Paller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!