You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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: #364 (comment)
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 the ANY(@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)}
CREATETYPECOLORSAS ENUM('red', 'green', 'blue');
CREATETABLEaccounts (
id BIGSERIALPRIMARY KEY,
name VARCHAR(50) NOT NULL,
email VARCHAR(50) UNIQUE NOT NULL,
active BOOLEANNOT NULL,
fav_color COLORS,
fav_numbers INTEGER[],
properties JSONB,
created_at TIMESTAMP WITH TIME ZONENOT NULL
);
SQL queries
-- name: SelectAllAccountsByFilter :manySELECT*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 = ANY(@fav_colors::COLORS[]) ELSE TRUE END)
;
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: #364 (comment)
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 the
ANY(@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
The text was updated successfully, but these errors were encountered: