Thread: How are jsonb_path_query SRFs $.datetime() defined ?

How are jsonb_path_query SRFs $.datetime() defined ?

From
Markur Sens
Date:
Hi,

In the regression test I see tests the one below [1], but generally, jsonb_path_query is a SRF,
and the definition in pg_proc.dat has it as such [0], looking at the implementation it doesn’t look like it calls jsonb_query_first behind the scenes (say if it detects it’s being called in  SELECT), which would explain it.

How would I re-create this same behaviour with say another $.func() in jsonb or any SRF in general.

{ oid => '4006', descr => 'jsonpath query',
proname => 'jsonb_path_query', prorows => '1000', proretset => 't',
prorettype => 'jsonb', proargtypes => 'jsonb jsonpath jsonb bool',
prosrc => 'jsonb_path_query' },


select jsonb_path_query('"10-03-2017"', '$.datetime("dd-mm-yyyy")');
jsonb_path_query
------------------
"2017-03-10"
(1 row)