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.1.1 db/functions/audit_view_as_json_v01.sql
renalware-core-2.1.0 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.167 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.166 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.165 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.164 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.163 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.162 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.161 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.160 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.159 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.158 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.157 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.156 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.155 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.153 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.152 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.151 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.149 db/functions/audit_view_as_json_v01.sql
renalware-core-2.0.148 db/functions/audit_view_as_json_v01.sql