layerware / hugsql

A Clojure library for embracing SQL
https://hugsql.org
Apache License 2.0
690 stars 54 forks source link

Doesn't handle psql casting without whitespace #30

Closed DrFriedParts closed 8 years ago

DrFriedParts commented 8 years ago

This is/should-be valid HugSQL because it is valid PSQL (works correctly in Yesql).

SELECT * FROM "the_table"
WHERE id = :key::bigint

But it will generate

SELECT * FROM "the_table" WHERE id = $1

instead of

SELECT * FROM "the_table" WHERE id = $1::bigint

The work-around is to add whitespace between the cast and the keyword, but it should support the concatenated format, no?

csummers commented 8 years ago

HugSQL tries to support Postgresql type casting with ::, but this is a bit of an edge case when it is immediately preceded by a :parameter because of HugSQL's :param-type:param-name syntax.

HugSQL does support escaping the colon with \:.

SELECT * FROM "the_table"
WHERE id = :key\:\:bigint

I'll keep looking at this and see if I can build in a work-around.

csummers commented 8 years ago

Support for this has been released in 0.4.5. Please confirm it works for you. Thanks for the report!