Open veqryn opened 2 months ago
I have the same issue: error while fetching products failed to encode args[5]: unable to encode []sqlc.CatalogProductType{\"base\", \"bundle\", \"group\", \"variant\"} into text format for unknown type (OID 37847): cannot find encode plan
It would be nice to know if there is any workaround. It's blocking my development. :(
@veqryn I found a work around for now, that is to force cast the types as text i.e. ::text
-- name: SelectAllAccountsByFilter :many
SELECT *
FROM accounts
WHERE (CASE WHEN @any_names::bool THEN name = ANY(@names::text[]) ELSE TRUE END)
AND (CASE WHEN @is_active::bool THEN active = @active ELSE TRUE END)
AND (CASE WHEN @any_fav_color::bool THEN fav_color::text = ANY(@fav_colors::text[]) ELSE TRUE END)
;
Version
1.27.0
What happened?
I am trying to create a query that will return a set of results based on a dynamic filter. I am using the pattern described here: https://github.com/sqlc-dev/sqlc/discussions/364#discussioncomment-55082 However, the query fails due to my ENUM.
I want the query to return any results where the color is any of the filtered colors. If I change the query to
fav_color = @fav_colors::COLORS
, then the query works. But it doesn't seem to like it when using theANY(@fav_colors::COLORS[])
, even though that pattern does work with the regular text/varchar field.The error message:
&fmt.wrapError{msg:"failed to encode args[5]: unable to encode []model.Colors{\"red\", \"blue\", \"green\"} into text format for unknown type (OID 16385): cannot find encode plan", err:(*fmt.wrapError)(0x14000092620)}
Example calling code:
Relevant log output
No response
Database schema
SQL queries
Configuration
Playground URL
https://play.sqlc.dev/p/8c40159dc90a74c0fcdb9b84a461e2d4e3608c7a6204f53c878303aa4f09ac0a
What operating system are you using?
macOS
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go