From: Karsten Hilbert <Karsten.Hilbert@gmx.net>
To: pgsql-general <pgsql-general@postgresql.org>
Subject: PG14: "is of" vs pg_typeof
Date: Sat, 23 Apr 2022 22:14:03 +0200
Message-ID: <YmReCy+ed+wTVpSJ@hermes.hilbert.loc> (raw)
PostgreSQL 14.2-1
Dear readers,
it used to be possible to say (inside plpgsql):
if _value is of (text, char, varchar, name) then
val_type := ''string'';
elsif _value is of (smallint, integer, bigint, numeric, boolean) then
val_type := ''numeric'';
elsif _value is of (bytea) then
val_type := ''data'';
elsif _value is of (text[]) then
val_type := ''str_array'';
else
raise exception ''cfg.set_option(text, any, text, text, text): invalid type of value'';
end if;
where _value is some typed value.
As of now (not sure when that started) PG 14 is giving me
gnumed_v23=> select 'a'::text is of (text, integer);
ERROR: syntax error at or near "of"
(same thing inside plpgsql)
where the log says
2022-04-23 19:58:33 GMT ERROR: 42601: syntax error at or near "of" at character 21
2022-04-23 19:58:33 GMT LOCATION: scanner_yyerror, scan.l:1176
2022-04-23 19:58:33 GMT STATEMENT: select 'a'::text is of (text, integer);
I can't find anything in the changelog saying that "is of"
was removed. For what it's worth, nothing in the docs ever
said it existed either (though it did, as per real life).
Now, pg_typeof is an alternative but that only goes so far:
it requires laboriously constructing an array on the right
hand side for the above use case, along the lines of:
select pg_typeof('a'::text) = any(ARRAY[pg_typeof(''::text), pg_typeof(''::name)]);
Is there anything obvious I am missing for easily
resurrecting the above "is of" use ?
Thanks,
Karsten
--
GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: Karsten.Hilbert@gmx.net
Subject: Re: PG14: "is of" vs pg_typeof
In-Reply-To: <YmReCy+ed+wTVpSJ@hermes.hilbert.loc>
References: <YmReCy+ed+wTVpSJ@hermes.hilbert.loc>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox