This is an artifact of the fact that PostgreSQL has two completely different kinds of SQL statements internally - plannable (SELECT
, INSERT
, UPDATE
, and DELETE
) and unplannable (everything else) statements.
Only plannable statements support query parameters.
PL/pgSQL implements variable substitutions into statements, like your bigobject
, using query parameters.
Because they aren't supported for non-plannable statements, no substitution is performed. So PL/pgSQL tries to execute the statement literally, as if you'd typed:
ALTER LARGE OBJECT bigobject OWNER TO postgres;
directly at the psql
prompt. It does not detect this as an error.
To work around this, use EXECUTE ... FORMAT
, e.g.
EXECUTE format('ALTER LARGE OBJECT %s OWNER TO postgres', bigobject);
See this related answer about COPY
.