Redshift : How to check table exists in Redshift using query ?

AWS Redshift @ Freshers.in

To check if a table exists in Amazon Redshift using a query, you can use the following SQL statement:

SELECT *
FROM pg_tables
WHERE schemaname = '<schema_name>'
AND tablename = '<table_name>';

Replace <schema_name> and <table_name> with the name of the schema and table you want to check for.

If the table exists, this query will return a row with information about the table. If the table does not exist, it will return an empty result set.

Alternatively, you can use the following SQL statement to check if a table exists without returning any information about the table:

SELECT EXISTS(
  SELECT 1
  FROM pg_tables
  WHERE schemaname = '<schema_name>'
  AND tablename = '<table_name>'
);

This query will return a boolean value – true if the table exists and false if it does not exist.

Author: user

Leave a Reply