Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Casting to some of the integer types generates invalid queries #17

Open
Bogdanp opened this issue Apr 25, 2019 · 0 comments
Open

Casting to some of the integer types generates invalid queries #17

Bogdanp opened this issue Apr 25, 2019 · 0 comments

Comments

@Bogdanp
Copy link

Bogdanp commented Apr 25, 2019

I use a bunch of custom domains in my application for validation and, because those domains get assigned custom type ids which this library doesn't (I think) support, I end up having to cast various columns. I've noticed that casting to int4 and int8 and text works just fine

> (sql-ast->string (scalar-expr-qq (select (cast 1 int4))))
"(SELECT CAST(1 AS int4))"

> (sql-ast->string (scalar-expr-qq (select (cast 1 int8))))
"(SELECT CAST(1 AS int8))"

> (sql-ast->string (scalar-expr-qq (select (cast 1 text))))
"(SELECT CAST(1 AS text))"

but casting to integer produces invalid sql:

(sql-ast->string (scalar-expr-qq (select (cast 1 integer))))
"(SELECT CAST(1 AS \"INTEGER\"))"

Note the quotes around INTEGER. In Postgres, executing this query produces an error:

ERROR:  42704: type "integer" does not exist
LINE 1: select cast(1 as "integer");
                         ^
LOCATION:  typenameType, parse_type.c:257
Time: 0.454 ms

Casting to smallint, bigint, decimal or numeric exhibits the same behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant