views:

61

answers:

1

Hi i want to store null value in a column.The column is nullable.The column value is not null always it depends on certain conditions.I dont want to write two queries in this case.I have tried None,null both but it gives me error saying worng type for double precision

+2  A: 

You do not say which Python / PostGreSQL interface module you're using -- there are several, not all DB API compliant. In DB API compliant modules, the None singleton is definitely the way to represent SQL NULLs on the Python side of things -- the API docs leave no doubt:

SQL NULL values are represented by the Python None singleton on input and output.

Maybe you're erroneously using, e.g., 'None' (with quotes making it a string, not the singleton None object), just as I imagine you're using 'null' with quotes in that erroneous attempt (if you didn't have quotes you'd get a NameError -- unless you've defined a variable by that name, which I sure hope you haven't!-).

We can be more helpful if you don't hide from us all the crucial data you're hiding: which PostgreSQL interface module, what's the table's schema, a simple snippet that fails, etc.

Alex Martelli
i m using psycopg2,python2.6 .I m defining the value of column in a variable x.i.e x=None.But while inserting it is giving error
ha22109
@ha22109, a simple attempt to reproduce this fails to repro it (i.e., my code works just fine) -- please edit your question to copy and paste the table's schema, your exact code snippet, and the error traceback, because clearly you must be doing something different, but trying to guess exactly what without this data that you could easily supply would be a total, unwarranted waste of time.
Alex Martelli