I have just noticed that the implementation of
CONVERT(text USING encoding_name)
tries to do database access during the grammar phase, viz it looks
up the encoding_name in pg_conversion and replaces it with an OID.
This is not workable; consider the situation where we are in an
already-aborted transaction. Using a pg_conversion OID in stored rules
isn't very acceptable either.
Unfortunately, I don't see any way offhand to fix this without an
initdb :-(.
regards, tom lane