Craig Ringer <> writes:
> What you appear to want is to access arbitrary fields of a record by name.

> The reason this isn't supported directly in PL/PgSQL is, AFAIK, mainly
> an issue of data typing. Each field in a record may be of a different
> type. So the return type would change based on the field accessed at
> execution time, which isn't something PL/PgSQL or regular SQL likes very
> much, as plans are formed and cached in part based on the types involved.

Right.  For better or worse, SQL is a strongly-typed language.  PG's
emphasis on datatype extensibility makes this constraint even tighter,
since you can't even tell e.g. which operators or functions would be
valid to apply to a field of indeterminate type.

> We could and probably should provide an operator or function to access
> records of a field in their text form by name. Patches are welcome ;-)

As was noted upthread, if you're satisfied with pretending all fields
of a record are text, it's not clear why you wouldn't be happy using
hstore instead.  Or JSON, which at least has heard of numbers as well
as text.  I think the current push to improve json/jsonb is driven
largely by the desire to handle scenarios of this sort.

                        regards, tom lane

Sent via pgsql-hackers mailing list (
To make changes to your subscription:

Reply via email to