Question: I want to check if statement in PostgreSQL:
IF (SELECT COUNT(*) FROM pg_language WHERE lanname = 'plpgsql') > 0 THEN PRINT 'Good' ELSE PRINT 'Bad' END IF;
Now this causes an error with IF.
As far as I read, this is because I need to use plpgsql to be able to use if, print and variables.
So far, I probably also had to use SELECT instead of printing. A.
How can I switch the language before executing this statement in plpgsql?
I want to test it first before I put it in a stored procedure. To check the code with variables, etc.
Edit:
It is decided:
DO LANGUAGE plpgsql $$ BEGIN IF (SELECT COUNT(*) FROM pg_language WHERE lanname = 'plpgsql') > 0 THEN RAISE NOTICE 'GOOD'; ELSE RAISE NOTICE 'BAD'; END IF; END; $$;
source share