Basics
Snippets
Check if database exists
Postgres
SELECT EXISTS (
SELECT 1
FROM pg_database
WHERE datname = 'your_database_name'
) AS database_exists;
MariaDB
SELECT EXISTS (
SELECT 1
FROM information_schema.schemata
WHERE schema_name = 'your_database_name'
) AS database_exists;
Check if table exists
Postgres
SELECT EXISTS (
SELECT 1
FROM pg_tables
WHERE schemaname = 'public'
AND tablename = 'your_table_name'
) AS table_exists;
MariaDB
SELECT EXISTS (
SELECT 1
FROM information_schema.tables
WHERE table_schema = 'your_database_name'
AND table_name = 'your_table_name'
) AS table_exists;
No comments to display
No comments to display