Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Friday, 16 February 2024

Create Temp table in Greenplum

In Greenplum, temporary tables can be created using the CREATE TEMP TABLE statement. Temporary tables in Greenplum are session-specific and are automatically dropped when the session ends.

Here's how you can create a temporary table in Greenplum:

CREATE TEMP TABLE TempTable (

    ID SERIAL PRIMARY KEY,

    Name VARCHAR(50)

);

This statement creates a temporary table named TempTable with columns ID and Name. The SERIAL type is used for the ID column to automatically generate unique values for each row.

You can then use this temporary table in your SQL queries within the same session:

INSERT INTO TempTable (Name) VALUES ('John'), ('Alice'), ('Bob');

SELECT * FROM TempTable;

To drop the temporary table explicitly when you're done using it (although this is not necessary as it will be dropped automatically when the session ends):

DROP TABLE TempTable;

That's it! You have created and used a temporary table in Greenplum.

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.