evagoras
07/01/2024, 6:10 PM:
) which are needed in a SELECT statement in queryExecute
. More details in thread...evagoras
07/01/2024, 6:10 PMqueryExecute
with a JDBC connection. In my case, Snowflake has a flattened JSON table column which you can query individual keys like this (assuming the column name is RECORD_CONTENT
)
return queryExecute(
"SELECT TOP 50
RECORD_CONTENT:booking_id AS id
FROM mytable
WHERE RECORD_CONTENT:status = :status",
{
status = {
value = arguments.status,
cfsqltype = "cf_sql_varchar"
}
}
);
However this creates issues when you add query params in the WHERE clause because they are separated by a column themselves. CF thinks that the selects are params, and ends up changing the query to this:
... SELECT RECORD_CONTENT?:booking_id ...
(notice the "?"), and the query fails complaining about not having enough query params.
I found this stackoverflow answer, which suggests escaping the columns, but it doesn't work for me: https://stackoverflow.com/questions/53308446/how-to-properly-escape-colon-in-queryexecute-sql-statement
Is there any other solution than the suggested second solution in that answer, which is change all the SELECT columns into queryparams? That does seem like a lot of work.
result = QueryExecute("
SELECT :selectBookingid AS ...
",
{ selectBookingid : "RECORD_CONTENT:booking_id"}
);
websolete
07/01/2024, 6:32 PMRECORD_CONTENT#chr(58)#status
or "...WHERE RECORD_CONTENT:" & "status..."
?evagoras
07/01/2024, 6:38 PMRECORD_CONTENT#chr(58)#booking_id AS id
turns into this:
SELECT TOP 50 RECORD_CONTENT? AS id
websolete
07/01/2024, 6:39 PMMatt Jones
07/01/2024, 6:40 PMRodney
07/01/2024, 6:40 PMevagoras
07/01/2024, 6:41 PMRodney
07/01/2024, 6:41 PMevagoras
07/01/2024, 7:37 PM