i'm a pythonic user. right now, i'm in trouble with restoring "string" into postgres. here's part of my code:
dataRecv = '3231334744323031363030313831340000000000'
device_id = bytearray.fromhex(dataRecv[0:(len(dataRecv)-10)]).decode()
and i got:
device_id = '213GD2016001813'
just like what i want.
but then i want to save it to postgresql with pyscopg2:
execute("INSERT INTO table (column) VALUES (device_id)")
commit()
which the "column" data type is char(20). The Error i got is here:
syntax error at or near "GD2016001813"
213GD20160018...
^
i already tried with casting string to the device_id with str(device_id)
and also add apostrophe (') in the beginning and the end of device id so it will be like this: VALUES ('device_id')
. but the result still the same, wether it will be error from this part:
213GD20160018...
^
or this part:
213GD20160018...
^
can you guys help me? thankyou
1)转换为字符串https://www.postgresql.org/docs/9.3/static/functions-formatting.html 2)检查列的格式也许只需要数字
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.