Thread: Re: pgsql: Improve default and empty privilege outputs in psql.

Re: pgsql: Improve default and empty privilege outputs in psql.

From
Christoph Berg
Date:
Re: Tom Lane
> Improve default and empty privilege outputs in psql.

I'm sorry to report this when 17.0 has already been wrapped, but this
change is breaking `psql -l` against 9.3-or-earlier servers:

$ /usr/lib/postgresql/17/bin/psql
psql (17rc1 (Debian 17~rc1-1.pgdg+2), Server 9.3.25)
Geben Sie »help« für Hilfe ein.

postgres =# \set ECHO_HIDDEN on
postgres =# \l
/******* ANFRAGE ********/
SELECT
  d.datname as "Name",
  pg_catalog.pg_get_userbyid(d.datdba) as "Owner",
  pg_catalog.pg_encoding_to_char(d.encoding) as "Encoding",
  'libc' AS "Locale Provider",
  d.datcollate as "Collate",
  d.datctype as "Ctype",
  NULL as "Locale",
  NULL as "ICU Rules",
  CASE WHEN pg_catalog.cardinality(d.datacl) = 0 THEN '(none)' ELSE pg_catalog.array_to_string(d.datacl, E'\n') END AS
"Accessprivileges"
 
FROM pg_catalog.pg_database d
ORDER BY 1;
/************************/

FEHLER:  42883: Funktion pg_catalog.cardinality(aclitem[]) existiert nicht
ZEILE 10:   CASE WHEN pg_catalog.cardinality(d.datacl) = 0 THEN '(none...
                      ^
TIP:  Keine Funktion stimmt mit dem angegebenen Namen und den Argumenttypen überein. Sie müssen möglicherweise
ausdrücklicheTypumwandlungen hinzufügen.
 
ORT:  ParseFuncOrColumn, parse_func.c:299


The psql docs aren't really explicit about which old versions are
still supported, but there's some mentioning that \d should work back
to 9.2:

      <para><application>psql</application> works best with servers of the same
       or an older major version.  Backslash commands are particularly likely
       to fail if the server is of a newer version than <application>psql</application>
       itself.  However, backslash commands of the <literal>\d</literal> family should
       work with servers of versions back to 9.2, though not necessarily with
       servers newer than <application>psql</application> itself.

\l seems a tad more important even.

Christoph



Re: pgsql: Improve default and empty privilege outputs in psql.

From
Tom Lane
Date:
Christoph Berg <myon@debian.org> writes:
> Re: Tom Lane
>> Improve default and empty privilege outputs in psql.

> I'm sorry to report this when 17.0 has already been wrapped, but this
> change is breaking `psql -l` against 9.3-or-earlier servers:
> FEHLER:  42883: Funktion pg_catalog.cardinality(aclitem[]) existiert nicht

Grumble.  Well, if that's the worst bug in 17.0 we should all be
very pleased indeed ;-).  I'll see about fixing it after the
release freeze lifts.

> The psql docs aren't really explicit about which old versions are
> still supported, but there's some mentioning that \d should work back
> to 9.2:

Yes, that's the expectation.  I'm sure we can think of a more
backwards-compatible way to test for empty datacl, though.

            regards, tom lane



Re: pgsql: Improve default and empty privilege outputs in psql.

From
Tom Lane
Date:
I wrote:
> Yes, that's the expectation.  I'm sure we can think of a more
> backwards-compatible way to test for empty datacl, though.

Looks like the attached should be sufficient.  As penance, I tried
all the commands in describe.c against 9.2 (or the oldest supported
server version), and none of them fail now.

            regards, tom lane

diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index faabecbc76..6a36c91083 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -6678,7 +6678,7 @@ printACLColumn(PQExpBuffer buf, const char *colname)
 {
     appendPQExpBuffer(buf,
                       "CASE"
-                      " WHEN pg_catalog.cardinality(%s) = 0 THEN '%s'"
+                      " WHEN pg_catalog.array_length(%s, 1) = 0 THEN '%s'"
                       " ELSE pg_catalog.array_to_string(%s, E'\\n')"
                       " END AS \"%s\"",
                       colname, gettext_noop("(none)"),