question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cant insert NULL into a json column if column is present

See original GitHub issue

Migrated issue, originally created by Michael Bayer (@zzzeek)

the serializer grabs None if it is present. for backwards compat we should support null() which currently also blows up:

from sqlalchemy import create_engine, Column, Table, MetaData, func, select, null
from sqlalchemy.dialects.postgresql import JSON

e = create_engine("postgresql://scott:tiger@localhost/test", echo='debug')
c = e.connect()
t = c.begin()

table = Table('json_test', MetaData(), Column('data', JSON))
table.create(c)

c.execute(table.insert(), [{"data": {"foo": "bar"}}, {"data": None}])

assert c.scalar(
    select([func.count('*')]).
    select_from(table).where(table.c.data == null()))


# probable workaround, also fails to invoke
#c.execute(table.insert(), [{"data": {"foo": "bar"}}, {"data": null()}])

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
sqlalchemy-botcommented, Nov 27, 2018

Michael Bayer (@zzzeek) wrote:

try sqlalchemy.null() instead.

0reactions
sqlalchemy-botcommented, Nov 27, 2018

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
Read more comments on GitHub >

github_iconTop Results From Across the Web

mysql JSON_SET can't insert into column with NULL value(5.7+)
Tried to set the column default to {} , but it is not allowed. My current work around is to set NULL to...
Read more >
Mysql temp table insert from json can't handle null values
I manage to detect if the value is null using an in-line IF statement, then I try to cast an actual SQL NULL...
Read more >
ORA-01400: cannot insert null into (string) | TekStream Solutions
According to Oracle, a null value can appear in columns of any datatype as long as it is not set to the value...
Read more >
Solve common issues with JSON in SQL Server
Answer. JSON_VALUE is designed to return small scalar values. Generally the function returns NULL instead of an overflow error. If you want to...
Read more >
Handling JSON null and empty arrays and objects - IBM
Null values · id - If the property is defined as nillable in the schema, then it will be set to null. ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found