Has anyone gotten this to work? I have a python dictionary that I want to insert into a sql table that has a column of datatype jsonb, but I can't convert the dictionary to the right datatype to get the system.db.runPrepUpdate() function to work.
The error that I get is :
" ERROR: column "quality" is of type jsonb but expression is of type character varying
Hint: You will need to rewrite or cast the expression.
import json
dc = {'test':'test'}
name = 'BRYSON1_RTU.AGAFLOW.DP:0'
stg = """update acm_test.acm_test_points set quality = ? where name = ? and device_id = 712"""
args = [dc,name]
system.db.runPrepUpdate(stg,args,'test')
dc = json.dumps({'test':'test'})
name = 'BRYSON1_RTU.AGAFLOW.DP:0'
stg = """update acm_test.acm_test_points set quality = ? where name = ? and device_id = 712"""
args = [dc,name]
system.db.runPrepUpdate(stg,args,'test')
dc = system.util.jsonEncode({'test':'test'})
name = 'BRYSON1_RTU.AGAFLOW.DP:0'
stg = """update acm_test.acm_test_points set quality = ? where name = ? and device_id = 712"""
args = [dc,name]
system.db.runPrepUpdate(stg,args,'test')
What I’ve found so far is that its unfortunate that psycopg2 is not avail (a C library) to use because this library makes it a little more seamless with python to push jsonb datatypes.
Basically we just need more syntax to if you can’s use the Json module from psycopg2
## WORKS:
stg = """update test.test_json_table set jsonb = '{"test44":"test44"}'::jsonb"""
system.db.runUpdateQuery(stg,'test')
# WORKS :
stg = """insert into test.test_json_table values (%s);""" %"""'{"test1":"test1"}'::jsonb"""
system.db.runUpdateQuery(stg,'test')```