pgrx icon indicating copy to clipboard operation
pgrx copied to clipboard

Database error: no binary output function available for type pksuid

Open Fyko opened this issue 2 years ago • 4 comments

Howdy folks! I'm writing a plugin to create a prefixed KSUID and I'm running into an issue:

Error: error returned from database: no binary output function available for type pksuid

Caused by:
    no binary output function available for type pksuid

This is when performing a query with sqlx. I have no issues when running queries via cargo pgrx run. My type: https://github.com/sycertech/pksuid/blob/main/pksuid/src/sqlx.rs Is there something I need to implement pgrx-side? Or is this something with sqlx?

Relevant Files https://github.com/sycertech/prefixed-ksuid/blob/1e2097299e1066f9deb73c4471e1659f3aedaf92/pksuid-example/src/main.rs https://github.com/sycertech/prefixed-ksuid/blob/1e2097299e1066f9deb73c4471e1659f3aedaf92/pksuid/src/lib.rs https://github.com/sycertech/prefixed-ksuid/blob/1e2097299e1066f9deb73c4471e1659f3aedaf92/pksuid-extension/src/lib.rs

Fyko avatar Dec 26 '23 19:12 Fyko

We've been chatting about this on Discord a bit. pgrx doesn't yet support a safe interface for also implementing a type's SEND and RECEIVE functions, so you gotta do that yourself. Which then means you can't use #[derive(PostgresType)] and have to do a lot of additional manual effort.

Sounds like you were doing that once via:

yeah this is how i was doing it before https://github.com/sycertech/pksuid/tree/67081388e686f84f80c978d06d6641202d8c2b5e/src wrt implementing pgtype, into/fromdatum, etc.

So you'll want to head back in that direction and then add the send/receive functions, which will be akin to:

#[pg_extern]
fn send(input: MyType) -> Vec<u8> {
    ... convert input to bytes ...
}

/// this one is funky
#[pg_extern] 
fn recv(internal: Internal) -> MyType {
   let string_info = unsafe { StringInfo::from_pg(internal.get().unwrap() as *mut pg_sys::StringInfoData) };
   ... take data from `string_info` and convert to MyType ...
}

If you get past your problem with this approach, let us know and we'll update our hexint example to also do this... which was clearly an oversight.

eeeebbbbrrrr avatar Dec 26 '23 20:12 eeeebbbbrrrr

Did someone actually manage to fix this?

turulix avatar Feb 03 '25 08:02 turulix

Did someone actually manage to fix this?

I did, in PR https://github.com/pgcentralfoundation/pgrx/pull/2068

LucaCappelletti94 avatar May 17 '25 07:05 LucaCappelletti94

This issue should now be closed as PR #2068 has been merged.

LucaCappelletti94 avatar Jun 01 '25 08:06 LucaCappelletti94