Search Postgresql Archives

Re: use null or 0 in foreign key column, to mean "no value"?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> On 27 Jun 2015, at 5:59, Robert Nikander <rob.nikander@xxxxxxxxx> wrote:
> In application code, prepared statements want to say: `select * from items where color_id = ?` and that `?` might be a int or null, so that doesn’t work. 

You could add another parameter to test which expression to 'activate' in the query, something like:

select * from items where ('notnull' = ? and color_id = ?) or ('null' = ? and color_id is null);

Of course, with those _positional_ query parameters that means you need to add the same value TWICE into the query. You wouldn't need to with _named_ query parameters, if those are available to you.

Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll find there is no forest.



-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux