piccolo-orm / piccolo

A fast, user friendly ORM and query builder which supports asyncio.
https://piccolo-orm.com/
MIT License
1.38k stars 89 forks source link

Compound unique indexes #1045

Open Forceres opened 1 month ago

Forceres commented 1 month ago

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

sinisaos commented 1 month ago

@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.

Forceres commented 1 month ago

@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)