pgrx icon indicating copy to clipboard operation
pgrx copied to clipboard

Support for `internallength` attribute for fixed-size Custom Types

Open LucaCappelletti94 opened this issue 7 months ago • 4 comments

Hi,

With PR #2068, I have added support for the binary representation for varlena types.

I would like to also add support for fixed-size types, but I am not sure whether the CBOR serialization makes any compression attempt that would turn an apparently fixed-size type into a de-facto varlena type.

I understand that several traits currently derived for varlena types would have to be implemented separately for these fixed-size types - other than that are there any other particular difficulties you foresee?

My plan is to add a decorator like #[internallength(usize)], derive all of the necessary types (including assert_eq(serialized.len(), expected_internal_length) every time I serialize or deserialize to catch errors early) and that should be about it.

Do let me know what do you think of it.

Best, Luca

LucaCappelletti94 avatar May 19 '25 17:05 LucaCappelletti94

pgrx supports fixed-size types already. You can see in pgrx-tests/src/tests/complex.rs. There's some boilerplate necessary, but you can do it today.

eeeebbbbrrrr avatar Jun 28 '25 14:06 eeeebbbbrrrr

In the example you linked it is handled by asking the user to manually define the whole set of features, right?

My idea was to simply extend the derive macro to add support for deriving all relevant aspects of such types automatically.

LucaCappelletti94 avatar Jun 28 '25 14:06 LucaCappelletti94

We are unable to use PostgresType derive and then pg_binary_protocol derive if we go the route of complex.rs example. And that just balloons up the boilerplate needed. Therefore, this is much necessary.

pksunkara avatar Nov 10 '25 01:11 pksunkara

A possible duplicate of this issue is #143

pksunkara avatar Nov 10 '25 01:11 pksunkara