We curently are storing JSON data (logs) in a text field in our database. Due to some new requirements, we would love to use the JSONB data type instead. Doing some testing we had everything working using a standard INSERT:
This works great, but when we moved to CFQUERYPARAM, we received an error that the data type of VARCHAR was invalid for JSONB. While we understand JSONB is stored as a binary, when you insert it, it is actually just text.
Lucee: 5.3.9.133
PostgreSQL Driver: 42.2.20
QUESTION: What data type should we be using when using CFQUERYPARAM?
@wwilliams If you try to insert data using sqltype -varchar then you must need to insert value data based upon the varchar length. otherwise it causes an error or please try to the sqltype - text
Thanks Mark. That did allow us to add the JSON into the database using a cfqueryparam. Now the issue is that it causes the data to lose the JSONB functionality b/c json_build_object creates a key : value pair. Using your example, all that is stored is:
“data”: “{JSON DATA STRINGIFIED}”
I since have tried a number of other functions and I still have ended up sticking with the old faithful TEXT data type for the original field.
So the data we are storing is complicated (compared to key / value). The data is about 5 levels deep and has structs and arrays. Based on what we are seeing, the only way to handle this is without cfqueryparam and we have decided to just stay with the TEXT column for now.
That is awesome! I didn’t know there was an “other” cfsqltype option. I typically use cfdocs.com for ref and this is the first time I have ever come across something that is not within their docs. I’ll shoot them an email and let them know.