Fork me on GitHub
#sql
<
2022-05-29
>
Benjamin15:05:49

what is the typical way to pass an array (for IN :foos ) as query parameters? I am making requests to redshift-data api (not using the jdbc driver)

Benjamin15:05:24

{:Sql "select *
from public.currency
where stat = 'crypton.transfer.roll_entries'
  and ingest_ts > date '2022-05-29'
  and s_data.\"unix_day\" IN :days
  and version like '66.%'
limit 10"
        :Parameters
        [{:name "days"
          :value (str "( " (str/join ", " [19140 19139]) " )")}]}
"ERROR: syntax error at or near \"$1\"\n Position: 139"

seancorfield17:05:48

What database libraries are you using? I'd use HoneySQL to build the whole [SQL & params] vector -- it understands [:where [:in :days data]] (although you can't use a named parameter here -- you have to let HoneySQL generate the ? placeholders).

emccue17:05:37

If you use postgres you can use a single ? and pass an array (not a vector or a list - java array) and that works

emccue17:05:57

honeysql's approach orks the most generically though

Benjamin07:05:08

alright thanks