Thread: PG14: "is of" vs pg_typeof
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
Am Sat, Apr 23, 2022 at 10:14:03PM +0200 schrieb Karsten Hilbert: > 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). Oh, wait, https://www.postgresql.org/message-id/1129826.1605805700@sss.pgh.pa.us is that it ? It is gone ? Alright, alright, https://www.postgresql.org/message-id/1052846.1605802012@sss.pgh.pa.us I am rewriting my code already. Interesting how one discovers the proper search strategy only eventually, *after* asking for help. Anyway, so there, "IS OF" (the old PG one, at any rate) is gone. Thanks, Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B
On 4/23/22 13:14, Karsten Hilbert wrote: > PostgreSQL 14.2-1 > > Dear readers, > > 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). It works through version 13. I also am not seeing, yet, where it was removed in 14. > 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 > > -- Adrian Klaver adrian.klaver@aklaver.com
On 4/23/22 13:36, Karsten Hilbert wrote: > Am Sat, Apr 23, 2022 at 10:14:03PM +0200 schrieb Karsten Hilbert: > >> 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). > > Oh, wait, > > https://www.postgresql.org/message-id/1129826.1605805700@sss.pgh.pa.us > > is that it ? It is gone ? > > Alright, alright, > > https://www.postgresql.org/message-id/1052846.1605802012@sss.pgh.pa.us > > I am rewriting my code already. Interesting how one discovers > the proper search strategy only eventually, *after* asking for > help. Also the actual commit: https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=926fa801ac9eb54c5275472271ec63a059904698 > > Anyway, so there, "IS OF" (the old PG one, at any rate) is > gone. > > Thanks, > Karsten > -- > GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B > > -- Adrian Klaver adrian.klaver@aklaver.com
On 4/23/22 13:14, Karsten Hilbert wrote: > PostgreSQL 14.2-1 > > Dear readers, > 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 ? Actually it can be done as: select pg_typeof('test'::text) in ('text'::regtype, 'varchar'::regtype); ?column? ---------- t select pg_typeof(1::int) in ('text'::regtype, 'varchar'::regtype); ?column? ---------- f > > Thanks, > Karsten > -- > GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B > > -- Adrian Klaver adrian.klaver@aklaver.com
Am Sat, Apr 23, 2022 at 01:43:52PM -0700 schrieb Adrian Klaver: > > 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 ? > > Actually it can be done as: > > select pg_typeof('test'::text) in ('text'::regtype, 'varchar'::regtype); Found that, but thanks anyway. Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B