This is a duplicate of my stackoverflow question --
http://stackoverflow.com/questions/5602918/postgresql-select-null-values-in-sqlalchemy

Basically I have a (PostgreSQL) table --

test=> create table people (name varchar primary key, marriage_status
varchar) ;

test=> insert into people values ('Ken', 'married');
test=> insert into people values ('May', 'single');
test=> insert into people values ('Joe', NULL);

I want to select all people that are not known to be married, i.e.,
including those with NULL marriage_status.

This does not work --

test=> select * from people where marriage_status != 'married' ;
 name | marriage_status
------+-----------------
 May  | single
(1 row)

Of course this does --

test=> select * from people where marriage_status != 'married' or
marriage_status is NULL ;
 name | marriage_status
------+-----------------
 May  | single
 Joe  |

The problem is that I'm accessing it from SQLAlchemy with --

...filter(or_(people.marriage_status!='married',
people.marriage_status is None))

which gets translated to --

SELECT people.name as name, people.marriage_status as marriage_status
FROM people
WHERE people.marriage_status != %(status_1)s OR False
sqlalchemy.engine.base.Engine.... {'status_1': 'married'}

And does not work --

test=> select * from people where marriage_status != 'married' or
False;
 name | marriage_status
------+-----------------
 May  | single
(1 row)

Any tip will be highly appreciated!

Jerry

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to