check schema exists postgresql 1

check schema exists postgresql

SELECT schema_name FROM information_schema.schemata WHERE schema_name = 'name';

Here is what the above code is Doing:
1. We’re using the SELECT statement to select the schema_name column from the information_schema.schemata table.
2. We’re using the WHERE clause to filter the results to only show the row where the schema_name is equal to the name variable.
3. We’re using the IF statement to check if the query returned any results.
4. If the query returned any results, we’re using the RAISE NOTICE statement to output a message that the schema already exists.
5. If the query didn’t return any results, we’re using the CREATE SCHEMA statement to create a new schema with the name specified by the name variable.

Similar Posts