| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | Craig Ringer <craig(at)2ndquadrant(dot)com> |
| Cc: | Peter Krauss <ppkrauss(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org |
| Subject: | Re: need of anonymous record |
| Date: | 2014-05-04 14:30:57 |
| Message-ID: | 23777.1399213857@sss.pgh.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Craig Ringer <craig(at)2ndquadrant(dot)com> 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Stephen Frost | 2014-05-04 15:03:56 | Re: pgaudit - an auditing extension for PostgreSQL |
| Previous Message | Andrew Dunstan | 2014-05-04 14:24:54 | Re: 9.4 release notes |