Skip to content

Allow arrays as bytea values in bytea[], not just vecs #4357

Description

@GrantGryczan

I have found these related issues/pull requests

Relates to #876

Description

When a Postgres sqlx::query! parameter expects a bytea[], the passed value must be a Vec<Vec<u8>> or &[Vec<u8>]. This is extremely limiting. In my case, I have a Vec<[u8; 9]>, which is a single contiguous allocation. This vec contains a quantity of elements decided by user input, and it can reasonably be in the thousands. Attempting to use this value directly gives this error:

mismatched types
expected reference `&[std::vec::Vec<u8>]`
   found reference `&[[u8; 9]]`

I don't want to have to perform thousands of Vec allocations in order to perform this query.

Prefered solution

The ideal solution for my use case would be to support Vec<[u8; N]> and/or &[[u8; N]] for all N as allowed values for a bytea[].

I also would prefer not to needlessly dereference thousands of pointers in order to perform this query, so it would be great if arrays were allowed for the inner bytea values, not just slices.

Is this a breaking change? Why or why not?

I don't expect this to be a breaking change; it strictly removes cases of compiler errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions