I'm highly confused about the use of variables in postgres. From the psql command-line, I've executed:
DO $$
DECLARE
NEW_SCHEMA TEXT:= 'myschema';
BEGIN
RAISE NOTICE 'Value of NEW_SCHEMA: %', NEW_SCHEMA; -- A
DROP SCHEMA IF EXISTS NEW_SCHEMA; -- B
CREATE SCHEMA IF NOT EXISTS NEW_SCHEMA; -- C
END$$;
Gives me:
NOTICE: Value of NEW_SCHEMA: myschema
NOTICE: schema "new_schema" does not exist, skipping
DO
... so... at A, NEW_SCHEMA is interpreted as a variable, but at B and C, it is interpreted as a literal, and a new schema called NEW_SCHEMA is created.
How do I can I get psql to interpret variables as variables, not as literals.