Re: Idiot's query: proper way to handle NULL in SELECT query?
Federico Di Gregorio <fog-NGVKUo/i/[email protected]> Sun, 09 May 2010 12:27:26 +0200
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
On 09/05/2010 01:46, Frank Miles wrote:
> As I have slowly been converting my system to use the adaptation
> methods, I've been using some direct conversions to handle NULL
> data. It would be nice to be able to:
>
> cur.execute("SELECT {variable-list} FROM table WHERE var1 = %s AND ... ;", (variable1,...))
cur.execute("""SELECT {variable-list} FROM table
WHERE (var1 = %{variable1}s OR %{variable1}s IS NULL)
AND (var2 = %{variable2}s OR %{variable2}s IS NULL)
AND ... ",
{variable1: variable1, variable2: variable2, ...})
federico
--
Federico Di Gregorio fog-NGVKUo/i/[email protected]
God is real. Unless declared integer. -- Anonymous FORTRAN programmer
_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg
signature.asc
(application/pgp-signature, 262 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkvmjhgACgkQvcCgrgZGjeuLKgCfZ6bMIQPJuhwmQrtpuxdtRcFU RbYAoJ910E5+hubFMDqOU12IiUovI/aa =HR+v -----END PGP SIGNATURE-----