public inbox for [email protected]
help / color / mirror / Atom feedFrom: Marthin Laubscher <[email protected]>
To: David G. Johnston <[email protected]>
Cc: Tom Lane <[email protected]>
Cc: [email protected]
Subject: Re: Custom type's modifiers
Date: Thu, 27 Jun 2024 19:01:10 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAKFQuwZnhZPQgbL687qeT5sC3kjWJ4r9QQwqB1nU5xtLbOj=HQ@mail.gmail.com>
References: <[email protected]>
<[email protected]>
<[email protected]>
<CAKFQuwZnhZPQgbL687qeT5sC3kjWJ4r9QQwqB1nU5xtLbOj=HQ@mail.gmail.com>
On 2024/06/27, 18:13, "David G. Johnston" <mailto:[email protected]> wrote:
> A cast between two types is going to accept a concrete instance of the input type, in memory, as its argument and then produces a concrete instance of the output type, in memory, as output. If the input data is serialized the constructor for the input type will handle deserialization.
I confess to some uncertainty whether the PostgreSQL specific x::y notation and the standards based CAST(x AS y) would both be addressed by creating a cast. What you’re saying means both forms engage the same code and defining a cast would cover the :: syntax as well. Thanks for that.
If my understanding is accurate, it means that even when both values are of MyType the CAST function would still be invoked so the type logic can determine how to handle (or reject) the cast. Cast would (obviously) require the target type modifiers as well, and the good news is that it’s already there as the second parameter of the function. So that’s the other function that receives the type modifier that I was missing. It’s starting to make plenty sense.
To summarise:
- The type modifiers, encoded by the TYPMOD_IN function are passed directly as parameters to:-
- the type's input function (parameter 3), and
- any "with function" cast where the target type has type modifiers.
- Regardless of the syntax used to invoke the cast, the same function will be called.
- Depending on what casts are defined, converting from the external string format to a value of MyType will be handled either by the input function or a cast function. By default (without any casts) only values recognised by input can be converted to MyType values.
-- Thanks for your time – Marthin Laubscher
view thread (3+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Subject: Re: Custom type's modifiers
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox