Skip to content

Commit 1cfa3b6

Browse files
committed
Details of @unique smart tag
1 parent 326dbf9 commit 1cfa3b6

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/pages/postgraphile/smart-tags.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,41 @@ class: {
620620
comment on materialized view my_materialized_view is E'@foreignKey (key_1, key_2) references other_table (key_1, key_2)';
621621
```
622622
623+
##### @unique
624+
625+
_From PostGraphile 4.9.1_
626+
627+
Introduces a "fake" unique constraint, so `@unique col1,col2` is somewhat
628+
equivalent to the following, except it can also be applied to entities that
629+
cannot have unique constraints, e.g. views. It is up to you to ensure that your
630+
data is indeed unique on the given columns.
631+
632+
```sql
633+
-- `@unique col1,col2` is roughly equivalent to:
634+
ALTER TABLE foo ADD CONSTRAINT fake_unique UNIQUE (col1, col2);
635+
```
636+
637+
More than one `@unique` tag may be specified.
638+
639+
```json5
640+
class: {
641+
my_view: {
642+
tags: {
643+
unique: [
644+
"id",
645+
"org_id,slug"
646+
]
647+
// or:
648+
// unique: "id"
649+
}
650+
}
651+
}
652+
```
653+
654+
```sql
655+
comment on view my_view is E'@unique id\n@unique org,slug';
656+
```
657+
623658
##### Smart Tags on virtual constraints
624659
625660
You can also add smart tags on virtual constraints, for example adding the

0 commit comments

Comments
 (0)