sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Using `where x = $1::TEXT[]` breaks type checking

Open danthegoodman1 opened this issue 1 year ago • 2 comments

Version

1.24.0

What happened?

Compliation successful with invalid WHERE condition. In the following query creator_code is not a valid column (should be url_code). When using the in ($1::TEXT[]) condition it breaks the check and successfully compiles only for the query to throw errors at query time.

Relevant log output

No response

Database schema

No response

SQL queries

select user_id, url_code
from creators
where creator_code in ($1::TEXT[])
;

Configuration

No response

Playground URL

No response

What operating system are you using?

macos

What database engines are you using?

postgres

What type of code are you generating?

Go

danthegoodman1 avatar Dec 27 '23 14:12 danthegoodman1

fwiw I intended to do where url_code = any($1::TEXT[]) originally and stumbled over this, also get the error expected $1::STRING[] to be of type string, found type string[] (SQLSTATE 22023) when the column fix is applied.

danthegoodman1 avatar Dec 27 '23 14:12 danthegoodman1

This is indeed a bug with the standard built-in analyzer. I have confirmed the correct behavior (an error saying the creator_code column doesn't exist) when using the database-backed analyzer which is perhaps a plausible workaround for some users.

andrewmbenton avatar Jan 04 '24 00:01 andrewmbenton