[sqlite] select null values in python

33 views
Skip to first unread message

Fabio Spadaro

unread,
Mar 22, 2012, 11:32:49 AM3/22/12
to General Discussion of SQLite Database
Using sqlite3 python and I have a problem running a query.
My table has null values​​. Now if I do a 'select * from tablename' returns
to me as the result:
[(datetime.date (2012, 3, 22), buffer ptr <read-write 0x0000000003774B90,
0x0000000003774B58> at size 0, None, None, None, None, None, None)]
As you can see there are null values ​​that in python are None type.
If I want to run a query like "select * from tablename where field1 = Null"
returns no results and even if I run "select * from tablename where field1
= None" None because there is not in Sqlite. You should use an adapter or
something?

--
Fabio Spadaro

Try Sqlite Root a GUI Admin Tools for manage Sqlite Database:
www.sqliteroot.com
_______________________________________________
sqlite-users mailing list
sqlite...@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Marc L. Allen

unread,
Mar 22, 2012, 11:41:03 AM3/22/12
to General Discussion of SQLite Database
select * from tablename where field1 IS Null

Igor Tandetnik

unread,
Mar 22, 2012, 11:41:49 AM3/22/12
to sqlite...@sqlite.org
On 3/22/2012 11:32 AM, Fabio Spadaro wrote:
> If I want to run a query like "select * from tablename where field1 = Null"

select * from tablename where field1 is null;

NULL is never equal any value, not even another NULL.
--
Igor Tandetnik

Simon Slavin

unread,
Mar 22, 2012, 12:18:17 PM3/22/12
to General Discussion of SQLite Database

On 22 Mar 2012, at 3:41pm, Igor Tandetnik <itand...@mvps.org> wrote:

> On 3/22/2012 11:32 AM, Fabio Spadaro wrote:
>> If I want to run a query like "select * from tablename where field1 = Null"
>
> select * from tablename where field1 is null;
>
> NULL is never equal any value, not even another NULL.

So experiment with

SELECT * FROM tablename WHERE typeof(field1) = "null"

?

Simon.

Jean-Denis MUYS

unread,
Mar 22, 2012, 12:18:49 PM3/22/12
to General Discussion of SQLite Database

On 22 mars 2012, at 16:41, Igor Tandetnik wrote:

> On 3/22/2012 11:32 AM, Fabio Spadaro wrote:
>> If I want to run a query like "select * from tablename where field1 = Null"
>
> select * from tablename where field1 is null;
>
> NULL is never equal any value, not even another NULL.
> --
> Igor Tandetnik
>

Welcome to Igor's style. He never answers the question you don't ask :-)

I have come to learn and appreciate his socratic style. Thanks Igor.

In the meantime, you might be interested in something like

select * from tablename where field1 IS Null

Jean-Denis

Igor Tandetnik

unread,
Mar 22, 2012, 12:26:57 PM3/22/12
to sqlite...@sqlite.org
On 3/22/2012 12:18 PM, Jean-Denis MUYS wrote:
>
> On 22 mars 2012, at 16:41, Igor Tandetnik wrote:
>
>> On 3/22/2012 11:32 AM, Fabio Spadaro wrote:
>>> If I want to run a query like "select * from tablename where field1 = Null"
>>
>> select * from tablename where field1 is null;
>>
>> NULL is never equal any value, not even another NULL.
>> --
>> Igor Tandetnik
>>
>
> Welcome to Igor's style. He never answers the question you don't ask :-)
>
> I have come to learn and appreciate his socratic style. Thanks Igor.
>
> In the meantime, you might be interested in something like
>
> select * from tablename where field1 IS Null

I did show this very example, except lacking the whitespace in front and
differing in capitalization. I assume you feel those distinct
characteristics render your example more interesting than mine.
--
Igor Tandetnik

Marc L. Allen

unread,
Mar 22, 2012, 12:42:26 PM3/22/12
to General Discussion of SQLite Database
> I did show this very example, except lacking the whitespace in front
> and differing in capitalization. I assume you feel those distinct
> characteristics render your example more interesting than mine.

Or mine, which was sent minutes before Igor's. Hmph. ;)

Larry Brasfield

unread,
Mar 22, 2012, 1:55:52 PM3/22/12
to sqlite...@sqlite.org
On 22 March, Jean-Denis wrote:

> On 22 mars 2012, at 17:26, Igor Tandetnik wrote:
>
> > On 3/22/2012 12:18 PM, Jean-Denis MUYS wrote:
> >>
> >> On 22 mars 2012, at 16:41, Igor Tandetnik wrote:
> >>
> >>> On 3/22/2012 11:32 AM, Fabio Spadaro wrote:
> >>>> If I want to run a query like "select * from tablename where field1 = Null"
> >>>
> >>> select * from tablename where field1 is null;
> >>>
> >>> NULL is never equal any value, not even another NULL.
> >>> --
> >>> Igor Tandetnik
> >>>
> >>
> >> Welcome to Igor's style. He never answers the question you don't ask :-)
> >>
> >> I have come to learn and appreciate his socratic style. Thanks Igor.
> >>
> >> In the meantime, you might be interested in something like
> >>
> >> select * from tablename where field1 IS Null
> >
> > I did show this very example, except lacking the whitespace in front and differing in capitalization. I assume you feel those distinct characteristics render your example more interesting than mine.
> > --
> > Igor Tandetnik
>
> Well, my apology. I didn't read your example carefully enough. Shame on me. Let me retract my answer (except my praise for your Socratic style, which I will not retract even if it doesn't quite apply here).
>
> Jean-Denis

(I doubt Igor felt damaged or slighted. Shame is hardly due. He was
just having some gentle fun.)

I just wanted to chime in with appreciation for Igor's contributions,
especially that he often *does* answer the question not asked when that
is more germane than simply answering the OP's question. I often find
his replies instructive.

--
Larry Brasfield

Reply all
Reply to author
Forward
0 new messages