Sha256: 4ab2c012ce5ab77ef4c805f857f2f384e49712c16a37a9ba751856dcfb52ffa1

Contents?: true

Size: 672 Bytes

Versions: 161

Compression:

Stored size: 672 Bytes

Contents

CREATE OR REPLACE FUNCTION audit_view_as_json(view_name text)
  /*
  Converts the specified view into its json representation suitable for feeding for example
  into jQuery datatables plugin, or creating a historical snapshot.
  Example usage:
    select audit_view_as_json('reporting_bone_audit')
  TC 1.11.2017
  */
  RETURNS json
  LANGUAGE 'plpgsql'
  as $$
  DECLARE result json;
  BEGIN
  EXECUTE format('
  select row_to_json(t)
    from (
      select
        current_timestamp as runat,
        (select array_to_json(array_agg(row_to_json(d))
      )
    from (select * from %s) d) as data) t;
    ', quote_ident(view_name)) into result;
  return result;
END
$$;

Version data entries

161 entries across 161 versions & 1 rubygems

Version Path
renalware-core-2.0.127 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.126 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.125 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.124 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.123 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.121 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.120 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.119 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.118 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.117 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.116 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.115 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.113 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.112 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.111 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.110 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.109 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.108 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.106 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.105 db/functions/audit_view_as_json_v01.sql