sql

Bingen Galartza Iparragirre 2023-04-12T07:17:55.916979Z

Hi! I would like to update multiple table rows with different values in a single go. I found https://stackoverflow.com/questions/18936896/updating-multiple-rows-with-different-primary-key-in-one-query-in-postgresql, but I'm not sure if it can be built using Honeysql. Any hint?

Bingen Galartza Iparragirre 2023-04-12T07:26:06.682829Z

Or maybe I should just use next.jdbc/execute-batch` instead?

Marius 2023-04-12T14:01:18.638469Z

Is it always the same number of tables that need to be updated? The you could prepate a statement for that. If the number changes, then batch processing seems to be more suitable. What is the reason you want to update it in one go and how large is the number of rows to be updaed?

Bingen Galartza Iparragirre 2023-04-12T14:49:00.848099Z

It's always the same table and fixed subset of columns.

Bingen Galartza Iparragirre 2023-04-12T14:49:23.705529Z

The number of rows should be < 50

Bingen Galartza Iparragirre 2023-04-12T14:49:52.796329Z

I wanted to do it in a single go thinking on performance (less round trips to the DB)

Bingen Galartza Iparragirre 2023-04-12T14:50:32.241139Z

Not sure what you mean with "The you could prepate a statement for that.". Could you elaborate? thx 😄

xbrln 2023-04-12T19:46:54.179289Z

in HoneySQL, how can one write the PostgreSQL equivalent of

last_seen BETWEEN NOW() - INTERVAL '24 Hours' AND NOW()
I tried this,
[:between :last_seen [:- [:now] [:interval 24 :Hours]] [:now]]
but got, syntax error at or near "$3"

seancorfield 2023-04-13T15:30:58.754059Z

FYI: https://github.com/seancorfield/honeysql/issues/486

xbrln 2023-04-14T15:30:12.988079Z

thank you for adding this 🙂

xbrln 2023-04-14T15:32:51.783149Z

am actually still not sure how to use it. So if i have to add interval '12 hours' should I use it like [:interval 12 :Hours] ?

seancorfield 2023-04-14T18:08:55.281289Z

That commit adds examples in documentation and tests showing how to use it.

seancorfield 2023-04-12T20:09:17.040779Z

First off, are you asking about HoneySQL v1 or v2? Second, there's a dedicated #honeysql channel, just FYI.

seancorfield 2023-04-12T20:12:13.523029Z

The syntax you say you want is INTERVAL 'some string' which I'm not sure you can create with v2 right now. The [:interval ..] syntax is somewhat MySQL specific I think...

seancorfield 2023-04-12T20:16:52.599229Z

Feel free to create an issue on GitHub and I'll update the way that is handled.

xbrln 2023-04-12T20:27:23.308279Z

Thanks Sean!! am using v2 and I'll see if I can modify the query so I can avoid using the interval.