Thanks for the info.  I guess my big lesson here is: (plpg)sql is much more
statically typed than I thought.

I was hoping for a function like:

CREATE FUNCTION field_for_composite_value(record, text) RETURNS any AS $$
    return record[text]
$$ LANGUAGE plpython3u IMMUTABLE STRICT;

but pretty much all of the "pseudo-types" are unavailable to all four of
the built-in extension languages.  (In fact, "any" is so unsupported that
it's a syntax error here!)  I guess I need to figure out C extensions for
that.

The bigger picture is that I wanted to write something kind of like
to_json() which dumps composite values recursively, but with a different
format.  (There are also *_to_xml() functions, but unlike JSON, they output
composite values as plain strings like (a,,,b) -- and also only operate on
cursor/table/query/database, not individual values.)  I'm still playing
with these, and I'm not sure if I can use them to fake a
`field_for_composite_value()` function or not.

Thanks again.


- Ken

Reply via email to