Commit 0db03d5
query_analysis: allow defer_foreign_keys pragma on primary (#980)
This pragma is useful for turning off foreign keys as a oneshot
operation within current transaction.
Example from turso shell:
```
→ create table t(id);
→ create table t2(id, v references t(id));
```
```
-- First insert to t2 fails, because t has no row with value (6)
→ pragma foreign_keys=on; begin; insert into t2 values(5,6); insert into t values (6); commit;
Error: SQLite error: FOREIGN KEY constraint failed
```
```
-- First insert doesn't fail, because checking foreign keys is deferred
-- until the transaction finishes
→ pragma foreign_keys=on; begin; pragma defer_foreign_keys=true; insert into t2 values(5,6); insert into t values (6); commit;
OK
```1 parent c6a0d59 commit 0db03d5
2 files changed
Lines changed: 2 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
| 131 | + | |
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
145 | 144 | | |
146 | 145 | | |
147 | 146 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
134 | | - | |
| 134 | + | |
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
147 | | - | |
148 | 147 | | |
149 | 148 | | |
150 | 149 | | |
| |||
0 commit comments