From: | Anthony Bykov <a(dot)bykov(at)postgrespro(dot)ru> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Jsonb transform for pl/python |
Date: | 2017-10-25 11:51:00 |
Message-ID: | 20171025145100.3a19933f@anthony-24-g082ur |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi.
I've implemented jsonb transform
(https://www.postgresql.org/docs/9.5/static/sql-createtransform.html)
for pl/python.
1. '{"1":1}'::jsonb is transformed into dict {"1"=>1}, while
'["1",2]'::jsonb is transformed into list(not tuple!) ["1", 2]
2. If there is a numeric value appear in jsonb, it will be transformed
to decimal through string (Numeric->String->Decimal). Not the best
solution, but as far as I understand this is usual practise in
postgresql to serialize Numerics and de-serialize them.
3. Decimal is transformed into jsonb through string
(Decimal->String->Numeric).
An example may also be helpful to understand extension. So, as an
example, function "test" transforms incoming jsonb into python,
transforms it back into jsonb and returns it.
create extension jsonb_plpython2u cascade;
create or replace function test(val jsonb)
returns jsonb
transform for type jsonb
language plpython2u
as $$
return (val);
$$;
select test('{"1":1,"example": null}'::jsonb);
--
Anthony Bykov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
Attachment | Content-Type | Size |
---|---|---|
0001-jsonb_plpython-extension.patch | text/x-patch | 33.3 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Amit Kapila | 2017-10-25 11:59:56 | Re: Pluggable storage |
Previous Message | Pavel Stehule | 2017-10-25 09:55:18 | Re: pgbench - allow to store select results into variables |