Re: How to assemble all fields of (any) view into a string? - Mailing list pgsql-general

From Jim Nasby
Subject Re: How to assemble all fields of (any) view into a string?
Date
Msg-id 90ae74a2-da89-a79c-325f-e9234ed5030c@BlueTreble.com
Whole thread Raw
In response to Re: How to assemble all fields of (any) view into a string?  (Ken Tanzer <ken.tanzer@gmail.com>)
Responses Re: How to assemble all fields of (any) view into a string?  (Adrian Klaver <adrian.klaver@aklaver.com>)
List pgsql-general
On 9/7/16 6:07 PM, Ken Tanzer wrote:
> ERROR:  PL/Python functions cannot accept type record

Ugh, yeah... that won't work. plperl might be able to do it, but I
suspect you're going to be stuck pulling the size info out of
info_schema or the catalog.

Actually, there is a way you could hack this via plpython; pass the row
in as text as well as the relation (regclass is good for that). You
could then do plpy.execute('SELECT (%::%).*'.format(row_text,
relation)); that should give you a dict just like Adrian's example did.

It would be nice if there was a function that accepted something with a
row descriptor and spit out the details of the descriptor.
http://pgxn.org/dist/colnames/doc/colnames.html comes close; if you know
much about C at all it shouldn't be hard to add a function to that
extension that returned the full details of the row. That and converting
the row to JSON would make it relatively easy to accomplish what you
want in a plpgsql (or maybe even plsql) function.
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
855-TREBLE2 (855-873-2532)   mobile: 512-569-9461


pgsql-general by date:

Previous
From: Jim Nasby
Date:
Subject: Re: Clustered index to preserve data locality in a multitenant application?
Next
From: Jim Nasby
Date:
Subject: Re: IDE for function/stored proc development.