简体   繁体   中英

Sqlalchemy postgresql null and None convertion in JSONB typefield

I save 3 level dictionaries in postgresql with sqlalchemy as jsonb type:

{'result': {'key_0': {...}, 'key_1': {...}, None: {...}}

After querying row I have got None converted to string

{'result': {'key_0': {...}, 'key_1': {...}, u'null': {...}}

Is this sqlalchemy bug?

postgresql 9.4, sqlalchemy 1.0.8, ubuntu server 12.04.5

It looks about right to me.

In javascript (and hence json) I believe that dictionary indices get converted to strings. So - it generates something like:

myvar[null] = {...}

which becomes

myvar['null'] = {...}

In any case, seeing null used as a dictionary key would make me run for the hills. I would recommend against it.

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.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM