Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oBlro-0000av-D2 for pgsql-general@arkaria.postgresql.org; Wed, 13 Jul 2022 23:34:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oBlrl-00055i-Ut for pgsql-general@arkaria.postgresql.org; Wed, 13 Jul 2022 23:34:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oBlrl-00055Y-HQ for pgsql-general@lists.postgresql.org; Wed, 13 Jul 2022 23:34:01 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oBlri-0004EV-4H for pgsql-general@lists.postgresql.org; Wed, 13 Jul 2022 23:34:00 +0000 Received: by mail-pj1-x1031.google.com with SMTP id z12-20020a17090a7b8c00b001ef84000b8bso6291353pjc.1 for ; Wed, 13 Jul 2022 16:33:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yugabyte.com; s=google; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=hWCarGRasOpzuNqVk8qkxh2ywMnjZrbTpZ78QFPSc3c=; b=f5CZCVfAY1z98tWzRvyEZ+bRL1TQVDAa1b4oV9+/6Rg4r8/ErlMNd3QUPm2wk90CS6 b36bR2Pcfq+z349ML2yA6En1GZHg7ZAn554gHBhYYvQwyuv1vLrhfs5+XPZpN66zi2yt wEhS1hQ7NHo+C4V5CIhUWyUct+tRcrtbLO6LU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=hWCarGRasOpzuNqVk8qkxh2ywMnjZrbTpZ78QFPSc3c=; b=rrinhLqHe9PJbFa1X7Z4Mc+cyGNqzT6eGgKAUr7Vi+QKiRCctsl9KG5ZMHu8RjaTYR ls648UaW/foXnB0HI2J/vdS3knJmqypBzmKxH7xTKCCLbSY5vXmt5+xRVD/iPlCLHCJr yRsaIUalqLiZdw+cVnAXTgfpWlMo9z4Qgh1qP8Z/l1mzipr7Q1TMI6VCagaW942d4w0x E/BJF9lV6FoFvmk4ghQ4nTILPEQY0Kj7EelEX7Ebr9HBY2mSk4xJHuYYD9Bt6zB+Bzbt Sw7AwYiXPF/Tm1K2x2R5V86WM+Y0X1vyFYduooBL9JMhBk60TURL8OiWd+MQjh58nBv1 TLSQ== X-Gm-Message-State: AJIora+g4yKjwxfOm3nJ4d6aFeAZE7yC92za27aAQfh4zdsbLqIEGAQX I5kSd7dXcEZuUEWO7znTL++0Vg== X-Google-Smtp-Source: AGRyM1su4XbMI7N+FdaqT2pX/tHY0H3cx01Aa+3bjLDbnO4KOKtgji8FTWjMjM4MOs0odRw0lr7fZg== X-Received: by 2002:a17:902:ea0e:b0:16b:f92b:a3c3 with SMTP id s14-20020a170902ea0e00b0016bf92ba3c3mr5669687plg.10.1657755235157; Wed, 13 Jul 2022 16:33:55 -0700 (PDT) Received: from smtpclient.apple ([2601:646:101:7fda:4d17:6583:a65b:c20b]) by smtp.gmail.com with ESMTPSA id z7-20020a623307000000b00528c066678csm100873pfz.72.2022.07.13.16.33.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jul 2022 16:33:54 -0700 (PDT) From: Bryn Llewellyn Message-Id: <1FB02EB7-627B-4D1F-B024-AB275871517F@yugabyte.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_E1D5E3BD-6E9D-40E5-871A-B9FFFF23A57E" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Re: Seems to be impossible to set a NULL search_path Date: Wed, 13 Jul 2022 16:33:53 -0700 In-Reply-To: <39F830B0-612D-44EF-BD38-D23D518DAAE8@yugabyte.com> Cc: pgsql-general list To: "David G. Johnston" References: <4B5F24E6-2FF9-4964-BF07-C609DC38E377@yugabyte.com> <39F830B0-612D-44EF-BD38-D23D518DAAE8@yugabyte.com> X-Mailer: Apple Mail (2.3654.120.0.1.13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_E1D5E3BD-6E9D-40E5-871A-B9FFFF23A57E Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > bryn@yugabyte.com wrote: >=20 >> david.g.johnston@gmail.com wrote: >>=20 >> As for "schema identifiers" vs. "schema names" - they both seem = equally wrong. The list can very much contain sequences of characters = that when interpreted as an identifier and looked for in the = pg_namespace catalog do not find a matching entry and are therefore by = definition not the name of any known schema in that database. >>=20 >> Besides, I hazard to guess how many times we write "table name" and = "column name" in the documentation when your argument is that "table = identifier" and "column identifier" is the correct choice. No, rather = "name" and "identifier" in the context of database objects are known to = mean the same thing - the alphabetic name of the object. >=20 > Well, "putative" or "candidate" can be used to resolve your existence = criterion. But why bother? In my book, Bertie Wooster (or Bertram = Wilberforce Wooster if you prefer) is a perfectly fine candidate name in = the general English speaking culture. It's neither here nor there if = there happens to be any living person who has the name... >=20 > But never mind. If you'd like a diverting read on this topic, go here: >=20 > https://blogs.oracle.com/sql/post/a-collection-of-plsql-essays = >=20 > look for this, and download the PDF: >=20 > =C2=AB > Names vs identifiers >=20 > Databases are full of things: tables, sequences, columns, views, = PL/SQL units, what have you. Things have names and are manipulated by = mentioning the names. The programming languages SQL and PL/SQL use = identifiers, not names. Questions show many programmers are confused = about the difference. This note describes the relationships between = things, names, and identifiers. Once the programming rules are absorbed, = developers can write code faster and with less heartburn. > =C2=BB >=20 > It's written by a former colleague with whom I spent many happy hours = discussing the topic. >=20 > Over and out? Something has been nagging me since I sent this. I was sure that I=E2=80=99= d seen this: "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=E2=80=94but 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 =20 ------------- 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: https://www.postgresql.org/docs/current/datatype-oid.html =C2=AB 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. =C2=BB 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. --Apple-Mail=_E1D5E3BD-6E9D-40E5-871A-B9FFFF23A57E Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
bryn@yugabyte.com = wrote:

david.g.johnston@gmail.com wrote:

As for "schema identifiers" vs. "schema names" - they both = seem equally wrong. The list can very much contain sequences of = characters that when interpreted as an identifier and looked for in the = pg_namespace catalog do not find a matching entry and are therefore = by definition not the name of any known schema in that database.

Besides, I hazard to guess how many times we = write "table name" and "column name" in the documentation when your = argument is that "table identifier" and "column identifier" is the = correct choice.  No, rather "name" and "identifier" in the = context of database objects are known to mean the same thing - the = alphabetic name of the object.

Well, "putative" or "candidate" can be used to resolve your = existence criterion. But why bother? In my book, Bertie Wooster = (or Bertram Wilberforce Wooster if you prefer) is a perfectly fine = candidate name in the general English speaking culture. It's neither = here nor there if there happens to be any living person who has the = name...

But never mind. If you'd like a = diverting read on this topic, go here:

https://blogs.oracle.com/sql/post/a-collection-of-plsql-essays<= /a>

look for this, and download the = PDF:

=C2=AB
Names vs identifiers

Databases = are full of things: tables, sequences, columns, views, PL/SQL units, = what have you. Things have names and are manipulated by mentioning = the names. The programming languages SQL and PL/SQL use identifiers, not = names. Questions show many programmers are confused about the = difference. This note describes the relationships between things, = names, and identifiers. Once the programming rules are absorbed, = developers can write code faster and with less heartburn.
=C2=BB

It's written by a former colleague with whom I spent many = happy hours discussing the topic.

Over and out?

Something has been = nagging me since I sent this. I was sure that I=E2=80=99d seen this:

"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=E2=80=94but 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:
https://www.postgresql.org/docs/current/datatype-oid.html

=C2=AB
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.
=C2=BB

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.

= --Apple-Mail=_E1D5E3BD-6E9D-40E5-871A-B9FFFF23A57E--