piccolo icon indicating copy to clipboard operation
piccolo copied to clipboard

Compound unique indexes

Open Forceres opened this issue 1 year ago • 2 comments

Is here a way to create compound unique indexes and use them in insert.on_conflict(target=unique_constraint)?

Forceres avatar Jul 05 '24 20:07 Forceres

@Forceres You can use unique constraints in the on_conflict target argument as described here, but you need to add unique=True to each separate column in the table definition. The issue with adding a composite unique constraint to multiple columns at once will be resolved by this PR. For now, the workaround is to use raw sql (in migrations or script) to add a composite unique constraint, as described here.

sinisaos avatar Jul 06 '24 06:07 sinisaos

@Forceres You can use unique constraints in the on_conflict target argument as described here, but you need to add unique=True to each separate column in the table definition. The issue with adding a composite unique constraint to multiple columns at once will be resolved by this PR. For now, the workaround is to use raw sql (in migrations or script) to add a composite unique constraint, as described here.

Yeah, made compound indexes via raw SQL (not a good approach)

Forceres avatar Jul 08 '24 18:07 Forceres