PostgreSql json error
See original GitHub issueIn Ktorm 3.3,
I have a postgresql database with a table that has a column named ‘template’ that has a datatype of json.
import org.ktorm.jackson.json
import org.ktorm.schema.Table
object TestTable: Table<TestTable>("test_table") {
val id = varchar("id").primaryKey().bindTo { it.id }
val template = json<Template>("template").bindTo { it.template }
}
interface TestTable: Entity<TestTable> {
companion object: Entity.Factory<TestTable>()
var id: String
var template: Template?
}
I am able to successfully pull the model including the json field using the below query
fun findById(id: String): TestTable? { return database.sequenceOf(TestTable) .find { it.id eq id } }
However when I try to patch the table using the below query I get the following error
fun insertOrUpdateById(id: String, testTable: TestTable): Int {
return database.insertOrUpdate(TestTable) {
set(it.template, testTable.template)
onConflict {
set(it.template, testTable.template)
}
}
}
Ktorm; bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: ERROR: column \"template\" is of type json but expression is of type character varying\n Hint: You will need to rewrite or cast the expression.\n Position: 59
Do I need to do something specific in order to update the json value?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
syntax error when trying to query json documents in postgresql
But when I tried to select, got syntax error: template1=# select * from jsonTest where data->>city ...
Read more >12: 9.15. JSON Functions and Operators - PostgreSQL
When you query JSON data, the path expression may not match the actual JSON data structure. An attempt to access a non-existent member...
Read more >PostgreSQL: Insert into JSONB key failing with syntax error at ...
The reason is that the attributes of a JSON column are not database columns, so you cannot use them in the SET clause...
Read more >How to use the JSON Datatype in PostgreSQL - Data Virtuality
Learn to use the JSON datatype in PostgreSQL, using its great functionality to work with JSON ... An error is thrown by PostgreSQL...
Read more >Error Source — PostgREST 9.0.0 documentation
PostgREST will convert the MESSAGE , DETAIL , HINT and ERRCODE from the PostgreSQL error to JSON format and add an HTTP status...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey Vincent, thanks for the quick responses. I had to stub a lot of the data in my example due to it being corporate code so if it’s not entirely syntactically correct, thats why. Also I very much appreciate you telling me what the culprit could be otherwise I wouldn’t have been able to come up with the following workaround.
I created a custom SqlType for postgres’s Json type, the only difference I made was to the doSetParameter function, the rest of the class is the same implementation as the default
JsonSqlType
.This did the trick!
@hurui200320 Fixed in 3.4.1