Skip to content

How to implement binary input/output functions for a custom Postgres Type #2060

Description

@LucaCappelletti94

Hi,

At this time, it is my understanding that custom postgres types allow to define the INPUT and OUTPUT functions with signatures, in the case of a custom type PositiveU32:

CREATE  FUNCTION "positiveu32_in"(
	"input" cstring /* core::option::Option<&core::ffi::c_str::CStr> */
) RETURNS PositiveU32 /* core::option::Option<example_extension::PositiveU32> */
IMMUTABLE PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'positiveu32_in_wrapper';

and

CREATE  FUNCTION "positiveu32_out"(
	"input" PositiveU32 /* example_extension::PositiveU32 */
) RETURNS cstring /* alloc::ffi::c_str::CString */
IMMUTABLE STRICT PARALLEL SAFE
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'positiveu32_out_wrapper';

And that is fine if I were to submit queries that provide the column value as a JSON, but since I use diesel, the data is submitted in binary and therefore PostgreSQL searches for a function which accepts a binary signature (to my understanding). Not finding one, it raises the error: no binary input function available for type positiveu32.

How can I make the pgrx sql code generation produce the analogous binary functions? If needed, I am happy to attempt a PR, with some guidance.

It should not be related to this issue, but I feel necessary to specify that in diesel, I serialize the data using serde_cbor in order to serialize it to the same format used by pgrx, or at least that is my understanding.

Best,
Luca

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions