honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
2018-10-31T01:04:59.011300Z

Heyo, thanks for maintaining this library! Is there support for postgres type hints ala 0::numeric or ARRAY[1, 2, 3]::integer[]? If not, do you have any suggestions for a way to add them? I experimented with honeysql.core/raw which of course would work, but that looses the data structure of any nested sql expressions.

seancorfield 2018-10-31T01:07:50.012200Z

raw is the way to do this -- it accepts parameters in the most recent releases of HoneySQL so you shouldn't lose any structure.

seancorfield 2018-10-31T01:08:46.013400Z

HoneySQL has a guiding principle of being ANSI SQL compliant and delegating DB-specific syntax to other libraries (that choose to extend HoneySQL). There's a honeysql-postgres library out there I think?

2018-10-31T15:45:04.014300Z

Thank you for your response! I will give it a go and reach back if that works for me. I didn’t see anything related to types in honeysql-postgres but I’ll take another look.

jetmind 2018-10-31T15:50:36.015400Z

you should be able to do that using something like (honeysql.core/call :cast 0 :numeric)

2018-10-31T16:07:23.015900Z

ah excellent! That I think will fit the bill

seancorfield 2018-10-31T16:15:13.016200Z

Thanks @jetmind -- I hadn't thought about adding an explicit cast like that (I don't think I've ever needed a cast in my SQL code...?).

jetmind 2018-10-31T16:31:22.017400Z

In my experience it sometimes come up when dealing with jsonb values in postgres

seancorfield 2018-10-31T16:33:27.018500Z

Ah, I don't use PostgreSQL -- and that does seem to where I see most of the questions about what looks to me like weird syntax and weird data types 🙂

2018-10-31T16:54:22.019300Z

HoneySQL even has a “cast” format handler! [:cast :0 :integer]

jetmind 2018-10-31T17:48:03.020100Z

don't you need an #sql/call reader tag before the vector for this to work?

jetmind 2018-10-31T17:48:51.020900Z

oh, it does work automatically in the :where context, but not in the :select, for example