pllua / pllua-deprecated

[DEPRECATED] This repository is no longer maintained. Please follow https://github.com/pllua/pllua
197 stars 16 forks source link

json/jsonb transform #41

Open bjne opened 7 years ago

bjne commented 7 years ago

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 commented 7 years ago

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