What is TRANSFORM FOR TYPE?
-
05-01-2021 - |
Pregunta
PostgreSQL 11 introduces TRANSFORM FOR TYPE
, from these docs by HP, PostgreSQL 11 New_Features
postgres=# CREATE EXTENSION jsonb_plperl CASCADE ;
NOTICE: installing required extension "plperl"
CREATE EXTENSION
postgres=> CREATE OR REPLACE FUNCTION fperl(val jsonb)
RETURNS jsonb
TRANSFORM FOR TYPE jsonb
LANGUAGE plperl
AS $$
return $_[0] ;
$$ ;
CREATE FUNCTION
postgres=> SELECT fperl('{"1":1,"example": null}'::jsonb) ;
fperl
---------------------------
{"1": 1, "example": null}
(1 row)
But it seems this would work the very same way if I remove TRANSFORM FOR TYPE jsonb
Solución
That's a totally useless example. I believe what TRANSFORM FOR TYPE
is supposed to support is something like this,
postgres=> CREATE OR REPLACE FUNCTION fperl(val jsonb)
RETURNS jsonb
TRANSFORM FOR TYPE jsonb
LANGUAGE plperl
AS $$
return $_[0]->{foo};
$$ ;
SELECT fperl('{"foo":"bar"}'::jsonb) ;
You can see in the above that we actually see the jsonb object as a perl hash and can access the members.
jsonb_plperl
is the new stuff here. CREATE TRANSFORM
dates to PostgreSQL 9.5.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a dba.stackexchange