Category: Appsmith Support
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

Error: column is of type json but expression is of type character varying

Issue

I encountered an error when trying to process an SQL query to the database. The error suggests that the input for the “tracks” column only accepts JSON as valid input, but my input is of type character varying. However, in the corresponding params, I used JSON_OBJECT as the input type for the "tracks" column. I'm not sure what's causing the issue, and I've been advised to try running the query with Prepared Statements turned off.

Resolution

After analyzing the error response, it was discovered that the input for the "tracks" column only accepts JSON as valid input, however, the current input is of type character varying. The input params for the "tracks" column is of type JSON_OBJECT, which suggests that the issue is with the insert query.

To resolve the issue, Prepared Statements should be turned off and the insert query should be updated to properly format the "tracks" column as JSON. The correct format for the insert query should be as follows:

INSERT INTO album (name, artist, release_date, tracks) VALUES ('Album Name', 'Artist Name', '2022-04-22', '{"Track Name": "Track Description"}');

Note that the tracks column is now formatted as a JSON object with key-value pairs enclosed in curly braces {}. The contents of each key-value pair should be enclosed in double quotes "" and separated by a colon :. The entire object should also be enclosed in double quotes "".

Once the insert query is properly formatted, the data should be successfully inserted into the database without error.