Skip to content

Instantly share code, notes, and snippets.

@quintessence
Created February 18, 2015 03:52
Show Gist options
  • Save quintessence/f3f6afc8f23a57345e8a to your computer and use it in GitHub Desktop.
Save quintessence/f3f6afc8f23a57345e8a to your computer and use it in GitHub Desktop.
transformServers.sql
-- transforms JSONB row data to columns
CREATE OR REPLACE FUNCTION transformServers(data jsonb)
RETURNS SETOF RECORD as $$
DECLARE
serversSet RECORD;
BEGIN
return query
SELECT jsonb_to_recordset(data->'data') INTO
serversSet (
id bigint,
hostname text,
nickname text,
os text,
created text,
running text,
capacity_cpu_freq text,
description text,
location_ip text,
capacity_cpu_num text,
capacity_mem text,
current_version text,
os_detail text,
architecture text,
guid text,
capacity_disk jsonb,
network_interfaces jsonb,
url text
);
END;
$$ language plpgsql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment