public inbox for [email protected]
help / color / mirror / Atom feedAllowed to return possibly TOASTed datums?
4+ messages / 3 participants
[nested] [flat]
* Allowed to return possibly TOASTed datums?
@ 2024-12-14 13:28 Jan Behrens <[email protected]>
2024-12-14 17:01 ` Re: Allowed to return possibly TOASTed datums? Tom Lane <[email protected]>
0 siblings, 1 reply; 4+ messages in thread
From: Jan Behrens @ 2024-12-14 13:28 UTC (permalink / raw)
To: [email protected]
Hi,
I would like to implement a function that simply returns its argument
(for the unary plus operator of a custum data type).
Is it allowed to use the following function, assuming the data type is
TOASTable?
PG_FUNCTION_INFO_V1(mytype_pos);
Datum mytype_pos(PG_FUNCTION_ARGS) {
PG_RETURN_DATUM(GETARG_DATUM(0));
}
CREATE FUNCTION "mytype_pos"("mytype") RETURNS "mytype"
STRICT IMMUTABLE LANGUAGE c AS 'mylib.so', 'mytype_pos';
CREATE OPERATOR + (
rightarg = "mytype",
function = "mytype_pos"
);
Or do I need to always return a DETOASTed value? In addition to the
answer, I would like to know where I can find such information. It
seems to be difficult (for me) to find it in the source. Is there any
other documentation I can use, or any hints on WHERE in the source I
find more information about when to DETOAST and when not?
Also: Is my approach an idiomatic way to implement unary plus? Are there
pre-existing functions for that?
Many thanks in advance for your help and kind regards
Jan Behrens
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Allowed to return possibly TOASTed datums?
2024-12-14 13:28 Allowed to return possibly TOASTed datums? Jan Behrens <[email protected]>
@ 2024-12-14 17:01 ` Tom Lane <[email protected]>
2024-12-14 18:13 ` Re: Allowed to return possibly TOASTed datums? Ron Johnson <[email protected]>
0 siblings, 1 reply; 4+ messages in thread
From: Tom Lane @ 2024-12-14 17:01 UTC (permalink / raw)
To: Jan Behrens <[email protected]>; +Cc: [email protected]
Jan Behrens <[email protected]> writes:
> Is it allowed to use the following function, assuming the data type is
> TOASTable?
> PG_FUNCTION_INFO_V1(mytype_pos);
> Datum mytype_pos(PG_FUNCTION_ARGS) {
> PG_RETURN_DATUM(GETARG_DATUM(0));
> }
Absolutely. You can find things equivalent to that in the
core code, I think.
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Allowed to return possibly TOASTed datums?
2024-12-14 13:28 Allowed to return possibly TOASTed datums? Jan Behrens <[email protected]>
2024-12-14 17:01 ` Re: Allowed to return possibly TOASTed datums? Tom Lane <[email protected]>
@ 2024-12-14 18:13 ` Ron Johnson <[email protected]>
2024-12-14 21:37 ` Re: Allowed to return possibly TOASTed datums? Tom Lane <[email protected]>
0 siblings, 1 reply; 4+ messages in thread
From: Ron Johnson @ 2024-12-14 18:13 UTC (permalink / raw)
To: pgsql-generallists.postgresql.org <[email protected]>
On Sat, Dec 14, 2024 at 12:02 PM Tom Lane <[email protected]> wrote:
> Jan Behrens <[email protected]> writes:
> > Is it allowed to use the following function, assuming the data type is
> > TOASTable?
>
> > PG_FUNCTION_INFO_V1(mytype_pos);
> > Datum mytype_pos(PG_FUNCTION_ARGS) {
> > PG_RETURN_DATUM(GETARG_DATUM(0));
> > }
>
> Absolutely. You can find things equivalent to that in the
> core code, I think.
>
(I'm not a developer, so this is a curiosity question, not a challenge.)
Since the purpose of TOAST is just (I think) to store "large field values"
on disk by dividing into multiple chunks, what would be the purpose of
returning the TOASTed value to Jan's function?
--
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Allowed to return possibly TOASTed datums?
2024-12-14 13:28 Allowed to return possibly TOASTed datums? Jan Behrens <[email protected]>
2024-12-14 17:01 ` Re: Allowed to return possibly TOASTed datums? Tom Lane <[email protected]>
2024-12-14 18:13 ` Re: Allowed to return possibly TOASTed datums? Ron Johnson <[email protected]>
@ 2024-12-14 21:37 ` Tom Lane <[email protected]>
0 siblings, 0 replies; 4+ messages in thread
From: Tom Lane @ 2024-12-14 21:37 UTC (permalink / raw)
To: Ron Johnson <[email protected]>; +Cc: pgsql-generallists.postgresql.org <[email protected]>
Ron Johnson <[email protected]> writes:
> Since the purpose of TOAST is just (I think) to store "large field values"
> on disk by dividing into multiple chunks, what would be the purpose of
> returning the TOASTed value to Jan's function?
Probably not much. There are scenarios where not detoasting
saves work overall, because the object never has to get detoasted;
but I think that's rare. It'd probably look like
UPDATE t SET c = no_op_function(c) WHERE ...
which is something few people would write.
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2024-12-14 21:37 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-12-14 13:28 Allowed to return possibly TOASTed datums? Jan Behrens <[email protected]>
2024-12-14 17:01 ` Tom Lane <[email protected]>
2024-12-14 18:13 ` Ron Johnson <[email protected]>
2024-12-14 21:37 ` Tom Lane <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox