I want to check whether the table exists or not in the database.
IF NOT EXISTS (SELECT * from INFORMATION_SCHEMA.Tables WHERE Table_name = 'test') THEN
RAISE INFO 'Not exists';
else
RAISE INFO 'Exists';
end if;
Getting an error:
ERROR: syntax error at or near "IF"
DO
$do$
BEGIN
IF NOT EXISTS (SELECT * from INFORMATION_SCHEMA.Tables WHERE Table_name = 'test') THEN
RAISE INFO 'Not exists';
else
RAISE INFO 'Exists';
end if;
end;
$do$
You should surround your postgresql statements with block
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With