Re: proposal - operators ? and ->> for type record, and functions record_keys and record_each_text

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal - operators ? and ->> for type record, and functions record_keys and record_each_text
Date: 2021-03-08 22:44:24
Message-ID: CAFj8pRCVPm183t3K1HaR4pHiu3XdyQOQy7LhUzkCsNFCqmgkzA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

po 8. 3. 2021 v 23:12 odesílatel Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> napsal:

> Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
> > I found an interesting idea to have some basic functions and operators
> for
> > record type (similar to json, jsonb or hstore).
>
> I think this is a pretty bad idea, because there's no way to know what
> data type the result of -> should be. "Smash it all to text" is a hack,
> not a solution --- and if you find that hack satisfactory, you might as
> well be using json or hstore.
>

I wrote (and sent) an implementation of generic type, that can hold any
type in binary form, and that can reduce IO casts. It can be more effective
than text, but an usability is the same like json or text, because you have
to use explicit casts everywhere. I think other solutions are not possible,
because you don't know the real type before an evaluation.

>
> Most of the other things you mention are predicated on the assumption
> that the field set will vary from one value to the next, which again
> seems more like something you'd do with json or hstore than with SQL
> composites.
>

I am thinking about effectiveness in triggers. NEW and OLD variables are of
record type, and sometimes you need to do operation just on tupledesc. When
I work with a record type, I can do it, without any overhead. When I need
to use jsonb or hstore, I have to pay, because all fields should be
transformated.

Minimally the operator "?" can be useful. It allows access to statically
specified fields without risk of exception. So I can write universal
trigger with

IF NEW ? 'fieldx' THEN
RAISE NOTICE '%', NEW.fieldx ;

and this operation can be fast and safe

> regards, tom lane
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message 'Alvaro Herrera' 2021-03-08 23:02:39 Re: PATCH: Batch/pipelining support for libpq
Previous Message David G. Johnston 2021-03-08 22:37:16 Re: PATCH: Batch/pipelining support for libpq