← Back to team overview

openerp-community team mailing list archive

Re: NULL Integers

 

On 14/03/13 22:47, Holger Brunn wrote:

use a partial unique index:
http://www.postgresql.org/docs/9.1/interactive/indexes-partial.html

Yes, that works. Thank you.

Not an ugly hack, but should suit your needs.

Well, before I had:

_sql_constraints = [
('variety_code_uniq', 'unique(variety_code)', 'That variety code already exists!'),
]

And now I have instead:

def init(self, cr):
cr.execute("""SELECT indexname FROM pg_indexes WHERE indexname = 'product_unique_variety_code_idx'""")
    if not cr.fetchone():
        cr.execute("""CREATE UNIQUE INDEX product_unique_variety_code_idx
                      ON product_template (variety_code)
                      WHERE variety_code != 0""")

Furthermore, where the error message before was

 'That variety code already exists!'

now it is:

 Integrity Error
duplicate key value violates unique constraint "product_unique_variety_code_idx"
 DETAIL:  Key (variety_code)=(101) already exists.

I wouldn't call any of that pretty.

Martin



Follow ups

References