bryn@xxxxxxxxxxxx wrote: "Bllewell" in some catalog view where I expected the name of a role. I just found it in pg_proc. The spelling Bllewell with no quotes is the name of an o/s user on my MacBook. I don't know why it ends up in my MacBook's PG installation—but that's a story for a different day. My PG cluster has a database called demo. I just did this test: \c demo postgres -- What a pain to have to do this to get silent "if exists" behavior. do $body$ begin begin drop owned by "Exotic Me" cascade; exception when undefined_object then null; end; begin drop owned by """Exotic Me""" cascade; exception when undefined_object then null; end; end; $body$; create role "Exotic Me" login password 'p'; grant connect on database demo to "Exotic Me"; create role """Exotic Me""" login password 'p'; \c demo "Exotic Me" create schema s; create procedure s.p() language plpgsql as $body$ begin null; end; $body$; with c as ( select rolname as role_name from pg_roles union all select distinct proowner::regrole::text as role_name from pg_proc) select role_name from c where lower(role_name) like '%bllewell%' or lower(role_name) like '%exotic%'; This is the result: role_name ------------- Bllewell Exotic Me "Exotic Me" "Bllewell" Of course I understand why I see both Exotic Me with no quotes and "Exotic Me" with double quotes: I asked for it. But why do I see both Bllewell with no quotes and "Bllewell" with double quotes. Are there really two distinct roles with those two names? Or did pg_roles end up with the identifier for the exotic name Bllewell rather than the bare name itself? And on the disputed notion that the identifier for a name is a distinct phenomenon from the name itself, I noted this here: « The input functions for these types allow whitespace between tokens, and will fold upper-case letters to lower case, except within double quotes; this is done to make the syntax rules similar to the way object names are written in SQL. Conversely, the output functions will use double quotes if needed to make the output be a valid SQL identifier. » It comes close (but no cigar) to making the distinction. It uses both "object name" and "SQL identifier" and says (more or less) that a "SQL identifier" is the way an object name is written in SQL by double-quoting it. I'm using "exotic" as a tautological shorthand for what you *must* surround with double-quotes in SQL and PL/pgSQL to express what you want. |