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

2015-06-27 Thread Alban Hertroys
On 27 Jun 2015, at 5:59, Robert Nikander rob.nikan...@gmail.com 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

[GENERAL] use null or 0 in foreign key column, to mean no value?

2015-06-26 Thread Robert Nikander
Hi, (Maybe my subject line should be: `is not distinct from` and indexes.) In Postgres 9.4, I’ve got a table of ‘items’ that references a table ‘colors’. Not all items have colors, so I created a nullable column in items like: color_id bigint references colors There is also an index

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

2015-06-26 Thread Jan de Visser
On June 26, 2015 11:59:05 PM Robert Nikander wrote: Hi, (Maybe my subject line should be: `is not distinct from` and indexes.) In Postgres 9.4, I’ve got a table of ‘items’ that references a table ‘colors’. Not all items have colors, so I created a nullable column in items like:

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

2015-06-26 Thread David G. Johnston
On Friday, June 26, 2015, Robert Nikander rob.nikan...@gmail.com wrote: So… is this bad DB design to use null to mean that an item has no color? Should I instead put a special row in `colors`, maybe with id = 0, to represent the “no color” value? Or is there some way to make an index work

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

2015-06-26 Thread John McKown
On Fri, Jun 26, 2015 at 10:59 PM, Robert Nikander rob.nikan...@gmail.com wrote: Hi, (Maybe my subject line should be: `is not distinct from` and indexes.) In Postgres 9.4, I’ve got a table of ‘items’ that references a table ‘colors’. Not all items have colors, so I created a nullable