po 8. 3. 2021 v 23:12 odesÃlatel Tom Lane <t...@sss.pgh.pa.us> napsal:
> Pavel Stehule <pavel.steh...@gmail.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 >