Skip to content
This repository has been archived by the owner on Jan 4, 2021. It is now read-only.

json/jsonb transform #41

Open
bjne opened this issue Oct 23, 2016 · 1 comment
Open

json/jsonb transform #41

bjne opened this issue Oct 23, 2016 · 1 comment

Comments

@bjne
Copy link

bjne commented Oct 23, 2016

Would you consider adding json/jsonb transform support?
At the momement, I accomplish this with cjson, but would be nice if this dependency
could disappear.

@eugwne
Copy link
Member

eugwne commented Oct 24, 2016

There is a small example with hstore in pgfunctest.sql

do $$
local hstore = {
    fromstring = function(text)
        return fromstring('hstore',text)
    end,
    akeys = pgfunc('akeys(hstore)',{only_internal = false}),
    each = pgfunc('each(hstore)',{only_internal = false}) --orig:each(IN hs hstore, OUT key text, OUT value text)
}

local v = hstore.fromstring[[
    "paperback" => "542",
    "publisher" => "postgresql.org",
    "language"  => "English",
    "ISBN-13"   => "978-0000000000",
    "weight"    => "24.1 ounces"
]]

print(v)

for _,v in ipairs(hstore.akeys(v)) do
    print (v)
end

for hv in hstore.each(v) do
    print ("key = " .. hv.key .. "    value = "..hv.value)
end
 $$ language pllua;

You can try using jsonb in the same way

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants