@quereus/quereus 4.20.1 → 4.20.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/src/schema/schema-differ.d.ts.map +1 -1
- package/dist/src/schema/schema-differ.js +17 -69
- package/dist/src/schema/schema-differ.js.map +1 -1
- package/package.json +7 -4
- package/test/README.md +173 -0
- package/test/logic/01-basic.sqllogic +39 -0
- package/test/logic/01.1-select-projection-extras.sqllogic +130 -0
- package/test/logic/01.2-strings.sqllogic +43 -0
- package/test/logic/01.5-insert-select.sqllogic +237 -0
- package/test/logic/01.6-update-extras.sqllogic +118 -0
- package/test/logic/01.7-update-from.sqllogic +67 -0
- package/test/logic/01.8-delete-extras.sqllogic +122 -0
- package/test/logic/01.8.1-delete-range-cow.sqllogic +115 -0
- package/test/logic/01.9-query-expr-dml-gates.sqllogic +32 -0
- package/test/logic/01.9-query-expr-dml.sqllogic +171 -0
- package/test/logic/01.9-query-expr-values.sqllogic +111 -0
- package/test/logic/01.9.1-limit-over-dml-subquery.sqllogic +119 -0
- package/test/logic/02-filters.sqllogic +54 -0
- package/test/logic/02-smoke.sqllogic +62 -0
- package/test/logic/02.1-bind-parameters.sqllogic +223 -0
- package/test/logic/03-expressions.sqllogic +190 -0
- package/test/logic/03.1-quoted-identifiers.sqllogic +55 -0
- package/test/logic/03.4-defaults.sqllogic +554 -0
- package/test/logic/03.4.1-default-edge-cases.sqllogic +99 -0
- package/test/logic/03.5-tvf.sqllogic +61 -0
- package/test/logic/03.6-type-system.sqllogic +544 -0
- package/test/logic/03.6.1-numeric-text-comparison-coercion.sqllogic +244 -0
- package/test/logic/03.6.2-value-to-text.sqllogic +224 -0
- package/test/logic/03.7-bigint-mixed-arithmetic.sqllogic +65 -0
- package/test/logic/03.8-not-precedence.sqllogic +255 -0
- package/test/logic/03.9-is-bool-predicate.sqllogic +150 -0
- package/test/logic/03.9.1-is-bool-predicate-partial-index.sqllogic +34 -0
- package/test/logic/04-order-by.sqllogic +38 -0
- package/test/logic/04-transactions.sqllogic +239 -0
- package/test/logic/04a-savepoint-lazy-attach.sqllogic +122 -0
- package/test/logic/05-vtab_memory.sqllogic +50 -0
- package/test/logic/05.0.1-vtab-memory-unique-index-collation.sqllogic +34 -0
- package/test/logic/05.1-composite-pk-range-scan.sqllogic +147 -0
- package/test/logic/05.1.1-secondary-index-range-scan.sqllogic +56 -0
- package/test/logic/05.2-cast-seek-correctness.sqllogic +124 -0
- package/test/logic/06-builtin_functions.sqllogic +149 -0
- package/test/logic/06.1-string-functions.sqllogic +92 -0
- package/test/logic/06.1.3-like-glob-edges.sqllogic +53 -0
- package/test/logic/06.2-math-functions.sqllogic +82 -0
- package/test/logic/06.3-schema.sqllogic +48 -0
- package/test/logic/06.3.1-schema-all-schemas.sqllogic +39 -0
- package/test/logic/06.3.2-schema-foreign-keys.sqllogic +208 -0
- package/test/logic/06.3.3-introspection-tags.sqllogic +202 -0
- package/test/logic/06.3.3.1-introspection-tags-index.sqllogic +74 -0
- package/test/logic/06.3.4-view-info.sqllogic +378 -0
- package/test/logic/06.3.5-column-info.sqllogic +347 -0
- package/test/logic/06.3.6-schema-views.sqllogic +29 -0
- package/test/logic/06.4-schema-search-path.sqllogic +354 -0
- package/test/logic/06.4.1-schema-case-insensitive.sqllogic +83 -0
- package/test/logic/06.4.2-collation-extras.sqllogic +472 -0
- package/test/logic/06.4.2.1-collation-index-access-paths.sqllogic +140 -0
- package/test/logic/06.4.3-write-path-collation.sqllogic +99 -0
- package/test/logic/06.4.4-comparison-collation-precedence.sqllogic +342 -0
- package/test/logic/06.4.5-any-collate-declared-keys.sqllogic +92 -0
- package/test/logic/06.5-polymorphic-types.sqllogic +169 -0
- package/test/logic/06.5.1-conversion-functions.sqllogic +173 -0
- package/test/logic/06.5.2-scalar-minmax.sqllogic +16 -0
- package/test/logic/06.5.3-undeclared-return-type-comparison.sqllogic +244 -0
- package/test/logic/06.5.4-declared-return-type-builtins.sqllogic +288 -0
- package/test/logic/06.6-aggregate-extended.sqllogic +78 -0
- package/test/logic/06.7-json-extended.sqllogic +53 -0
- package/test/logic/06.8-json-path-operators.sqllogic +99 -0
- package/test/logic/06.9-json-canonical-key.sqllogic +65 -0
- package/test/logic/06.9.1-json-coerce-once.sqllogic +417 -0
- package/test/logic/06.9.1.1-json-coerce-once-index.sqllogic +39 -0
- package/test/logic/06.9.2-json-structural-equality.sqllogic +382 -0
- package/test/logic/06.9.2.1-json-structural-equality-index.sqllogic +76 -0
- package/test/logic/06.9.3-json-index-range-seek.sqllogic +205 -0
- package/test/logic/07-aggregates.sqllogic +193 -0
- package/test/logic/07.1-aggregate-filter-clause.sqllogic +12 -0
- package/test/logic/07.2-aggregate-order-by.sqllogic +11 -0
- package/test/logic/07.3-group-by-extras.sqllogic +602 -0
- package/test/logic/07.3.1-group-by-order-by-key.sqllogic +164 -0
- package/test/logic/07.3.2-grouped-select-list-shape.sqllogic +231 -0
- package/test/logic/07.4-group-by-filter-composite-pk.sqllogic +120 -0
- package/test/logic/07.5-sum-mixed-exact-and-float.sqllogic +151 -0
- package/test/logic/07.5-window.sqllogic +1941 -0
- package/test/logic/07.5.1-window-named.sqllogic +13 -0
- package/test/logic/07.5.2-window-nth-value.sqllogic +13 -0
- package/test/logic/07.6-subqueries.sqllogic +78 -0
- package/test/logic/07.6.1-subquery-extras.sqllogic +93 -0
- package/test/logic/07.7-and-or-short-circuit.sqllogic +58 -0
- package/test/logic/07.7-in-subquery-caching.sqllogic +174 -0
- package/test/logic/07.7-scalar-agg-decorrelation.sqllogic +197 -0
- package/test/logic/07.7.1-in-extras.sqllogic +158 -0
- package/test/logic/07.7.1-scalar-agg-decorrelation-filter.sqllogic +105 -0
- package/test/logic/07.7.2-scalar-agg-decorrelation-nested.sqllogic +115 -0
- package/test/logic/07.7.3-exists-in-select-decorrelation.sqllogic +107 -0
- package/test/logic/07.7.4-where-conjunct-ordering.sqllogic +121 -0
- package/test/logic/07.7.5-filter-lost-under-index-order.sqllogic +134 -0
- package/test/logic/07.7.6-correlated-predicate-scope.sqllogic +178 -0
- package/test/logic/07.7.7-join-source-scope-shadowing.sqllogic +137 -0
- package/test/logic/07.7.8-correlated-ref-to-computed-column.sqllogic +165 -0
- package/test/logic/07.7.9-conjunct-monotonicity.sqllogic +200 -0
- package/test/logic/07.8-correlated-subquery-edges.sqllogic +71 -0
- package/test/logic/07.8.1-correlated-in-decorrelation-gates.sqllogic +156 -0
- package/test/logic/07.9-in-value-list.sqllogic +154 -0
- package/test/logic/07.9.1-in-value-list-composite-index.sqllogic +38 -0
- package/test/logic/08-views.sqllogic +64 -0
- package/test/logic/08.1-semi-anti-join.sqllogic +191 -0
- package/test/logic/08.1-view-edge-cases.sqllogic +118 -0
- package/test/logic/08.1.1-uncorrelated-in-semijoin.sqllogic +251 -0
- package/test/logic/08.2-existence-flag-semijoin-recovery.sqllogic +197 -0
- package/test/logic/08.3-existence-flag-inner-recovery.sqllogic +102 -0
- package/test/logic/08.4-key-set-semi-join.sqllogic +447 -0
- package/test/logic/09-set_operations.sqllogic +244 -0
- package/test/logic/09.1-set-op-cross-collation.sqllogic +230 -0
- package/test/logic/10-distinct_datatypes.sqllogic +127 -0
- package/test/logic/10.1-ddl-lifecycle.sqllogic +203 -0
- package/test/logic/10.1.1-create-table-syntax-edges.sqllogic +47 -0
- package/test/logic/10.1.2-ddl-in-transaction.sqllogic +143 -0
- package/test/logic/10.1.2.1-add-constraint-in-transaction.sqllogic +59 -0
- package/test/logic/10.1.3-ddl-drop-in-transaction.sqllogic +187 -0
- package/test/logic/10.1.3.1-drop-constraint-in-transaction.sqllogic +45 -0
- package/test/logic/10.1.4-create-table-duplicate-constraint-names.sqllogic +149 -0
- package/test/logic/10.1.4-ddl-transaction-policy.sqllogic +314 -0
- package/test/logic/10.1.5-alter-add-constraint-minted-name-disambiguation.sqllogic +219 -0
- package/test/logic/10.1.5-create-index-lifecycle.sqllogic +72 -0
- package/test/logic/10.1.6-ddl-transaction-policy-index.sqllogic +143 -0
- package/test/logic/10.1.7-create-table-default-type-check.sqllogic +119 -0
- package/test/logic/10.1.8-alter-add-check-existing-rows.sqllogic +117 -0
- package/test/logic/10.2-column-features.sqllogic +365 -0
- package/test/logic/10.2.1-table-options-rejection.sqllogic +63 -0
- package/test/logic/10.2.2-default-collation-memory.sqllogic +30 -0
- package/test/logic/10.3-function-features.sqllogic +247 -0
- package/test/logic/10.4-schema-scale.sqllogic +168 -0
- package/test/logic/10.4.1-schema-scale-indexes.sqllogic +121 -0
- package/test/logic/10.5-indexes.sqllogic +164 -0
- package/test/logic/10.5.1-partial-indexes.sqllogic +526 -0
- package/test/logic/10.5.2-expression-indexes.sqllogic +34 -0
- package/test/logic/10.5.3-desc-index-ordering.sqllogic +130 -0
- package/test/logic/10.5.4-composite-pk-index-update-phantom.sqllogic +55 -0
- package/test/logic/10.5.5-index-name-uniqueness.sqllogic +76 -0
- package/test/logic/10.5.6-minmax-index-boundary.sqllogic +204 -0
- package/test/logic/10.5.7-implicit-unique-index-lifecycle.sqllogic +1216 -0
- package/test/logic/10.6-distinct-edge-cases.sqllogic +119 -0
- package/test/logic/100-predicate-normalization-edge-cases.sqllogic +238 -0
- package/test/logic/100.1-where-extras.sqllogic +163 -0
- package/test/logic/100.1.1-where-join-on-order-indexed.sqllogic +35 -0
- package/test/logic/101-builtin-mutation-kills.sqllogic +974 -0
- package/test/logic/101-transaction-edge-cases.sqllogic +395 -0
- package/test/logic/102-schema-catalog-edge-cases.sqllogic +252 -0
- package/test/logic/102-unique-constraints.sqllogic +145 -0
- package/test/logic/102.0.1-schema-catalog-indexed-table.sqllogic +32 -0
- package/test/logic/102.1-unique-edge-cases.sqllogic +111 -0
- package/test/logic/102.1.1-unique-index-creation-edge-cases.sqllogic +75 -0
- package/test/logic/102.2-unique-collation.sqllogic +181 -0
- package/test/logic/102.2.1-unique-collation-index-derived.sqllogic +305 -0
- package/test/logic/103-database-options-edge-cases.sqllogic +108 -0
- package/test/logic/103.1-pragma-boolean-values.sqllogic +126 -0
- package/test/logic/104-emit-mutation-kills.sqllogic +236 -0
- package/test/logic/105-vtab-memory-mutation-kills.sqllogic +754 -0
- package/test/logic/105.1-vtab-memory-index-mutation-kills.sqllogic +540 -0
- package/test/logic/106-constraint-extractor-mutation-kills.sqllogic +350 -0
- package/test/logic/107-temporal-arithmetic-mutation-kills.sqllogic +833 -0
- package/test/logic/108-cardinality-estimation.sqllogic +146 -0
- package/test/logic/108.1-analyze-name-resolution.sqllogic +102 -0
- package/test/logic/109-aggregate-physical-selection.sqllogic +103 -0
- package/test/logic/11-joins.sqllogic +86 -0
- package/test/logic/11.1-join-using.sqllogic +267 -0
- package/test/logic/11.2-comma-join.sqllogic +35 -0
- package/test/logic/11.3-index-nested-loop-join.sqllogic +305 -0
- package/test/logic/11.3-mismatched-collation-join.sqllogic +74 -0
- package/test/logic/11.4-hash-join-side-swap.sqllogic +118 -0
- package/test/logic/110-scan-emitter-mutation-kills.sqllogic +121 -0
- package/test/logic/110.1-scan-emitter-index-scan-kills.sqllogic +47 -0
- package/test/logic/12-empty-primary-key.sqllogic +124 -0
- package/test/logic/12-join_padding_order.sqllogic +58 -0
- package/test/logic/12.1-orderby-index-consumption.sqllogic +40 -0
- package/test/logic/13-cte.sqllogic +137 -0
- package/test/logic/13.1-cte-multiple-recursive.sqllogic +104 -0
- package/test/logic/13.10-cte-qualified-name.sqllogic +136 -0
- package/test/logic/13.11-unreferenced-dml-cte.sqllogic +414 -0
- package/test/logic/13.12-nested-dml-cte-rejected.sqllogic +280 -0
- package/test/logic/13.2-cte-bind-params.sqllogic +98 -0
- package/test/logic/13.3-cte-edge-cases.sqllogic +120 -0
- package/test/logic/13.4-cte-extras.sqllogic +98 -0
- package/test/logic/13.5-cte-join-order.sqllogic +166 -0
- package/test/logic/13.6-cte-dml-runs-once.sqllogic +318 -0
- package/test/logic/13.7-cte-sibling-visibility.sqllogic +227 -0
- package/test/logic/13.8-insert-with-clause-visibility.sqllogic +254 -0
- package/test/logic/13.9-schema-authored-cte-isolation.sqllogic +328 -0
- package/test/logic/13.9.1-schema-authored-schema-path-isolation.sqllogic +408 -0
- package/test/logic/14-utilities.sqllogic +168 -0
- package/test/logic/15-timespan.sqllogic +279 -0
- package/test/logic/15.1-semantic-ordering.sqllogic +960 -0
- package/test/logic/15.1.1-json-check-coercion.sqllogic +178 -0
- package/test/logic/15.1.2-semantic-ordering-index.sqllogic +41 -0
- package/test/logic/15.1.3-declared-form-write-contract.sqllogic +519 -0
- package/test/logic/16-epoch.sqllogic +187 -0
- package/test/logic/17-weekday-modifier.sqllogic +78 -0
- package/test/logic/18-json-string-escapes.sqllogic +86 -0
- package/test/logic/18-strftime-extended-formats.sqllogic +68 -0
- package/test/logic/20-empty-single-row.sqllogic +261 -0
- package/test/logic/21-null-edge-cases.sqllogic +227 -0
- package/test/logic/21.1-where-null-comparisons.sqllogic +151 -0
- package/test/logic/21.1.1-where-null-comparisons-secondary-index.sqllogic +35 -0
- package/test/logic/21.2-between-edges.sqllogic +157 -0
- package/test/logic/22-boundary-values.sqllogic +175 -0
- package/test/logic/23-self-joins-duplicates.sqllogic +74 -0
- package/test/logic/24-builtin-branches.sqllogic +611 -0
- package/test/logic/24.1-substr-extras.sqllogic +75 -0
- package/test/logic/24.2-random-extras.sqllogic +39 -0
- package/test/logic/25-aggregate-edge-cases.sqllogic +289 -0
- package/test/logic/25.1-nested-aggregates.sqllogic +74 -0
- package/test/logic/25.2-having-edge-cases.sqllogic +318 -0
- package/test/logic/25.3-aggregate-isnull-empty.sqllogic +16 -0
- package/test/logic/25.4-groupby-fd-constant-empty.sqllogic +55 -0
- package/test/logic/25.5-ungrouped-aggregate-column-free-select-item.sqllogic +196 -0
- package/test/logic/26-join-edge-cases.sqllogic +333 -0
- package/test/logic/26.1-left-join-isnull-on-notnull.sqllogic +26 -0
- package/test/logic/26.2-left-join-on-vs-where.sqllogic +67 -0
- package/test/logic/26.3-join-on-constants.sqllogic +61 -0
- package/test/logic/26.4-join-on-is-null-nullable.sqllogic +44 -0
- package/test/logic/27-window-edge-cases.sqllogic +206 -0
- package/test/logic/27.1-window-groups-frame.sqllogic +13 -0
- package/test/logic/27.2-window-exclude.sqllogic +13 -0
- package/test/logic/27.3-window-json-aggregation.sqllogic +66 -0
- package/test/logic/28-set-ops-sort-edge-cases.sqllogic +444 -0
- package/test/logic/28.1-compound-limit-offset.sqllogic +143 -0
- package/test/logic/28.2-orderby-expression-extras.sqllogic +698 -0
- package/test/logic/28.2-set-op-branch-types.sqllogic +217 -0
- package/test/logic/29-constraint-edge-cases.sqllogic +442 -0
- package/test/logic/29.1-column-level-conflict-clause.sqllogic +171 -0
- package/test/logic/29.2-table-level-pk-conflict-clause.sqllogic +113 -0
- package/test/logic/40-constraints.sqllogic +418 -0
- package/test/logic/40.1-pk-desc-direction.sqllogic +76 -0
- package/test/logic/40.2-check-extras.sqllogic +683 -0
- package/test/logic/41-alter-table.sqllogic +191 -0
- package/test/logic/41-fk-cascade-conflict-and-self-ref.sqllogic +263 -0
- package/test/logic/41-fk-cross-schema.sqllogic +155 -0
- package/test/logic/41-fk-extended-targets.sqllogic +173 -0
- package/test/logic/41-foreign-keys.sqllogic +1001 -0
- package/test/logic/41-generated-column-errors.sqllogic +225 -0
- package/test/logic/41-generated-column-extras.sqllogic +598 -0
- package/test/logic/41-generated-column-scope.sqllogic +329 -0
- package/test/logic/41-generated-columns.sqllogic +361 -0
- package/test/logic/41.1-alter-pk.sqllogic +230 -0
- package/test/logic/41.1-fk-collation-conflict.sqllogic +277 -0
- package/test/logic/41.10-alter-drop-column-foreign-key.sqllogic +274 -0
- package/test/logic/41.10.1-alter-drop-column-unique-index.sqllogic +169 -0
- package/test/logic/41.10.2-alter-drop-column-check-and-assertion.sqllogic +1616 -0
- package/test/logic/41.10.3-alter-drop-column-referencing-fk.sqllogic +292 -0
- package/test/logic/41.10.4-drop-object-expression-dependents.sqllogic +602 -0
- package/test/logic/41.11-deferred-fk-with-rename.sqllogic +232 -0
- package/test/logic/41.12-alter-default-coercion.sqllogic +200 -0
- package/test/logic/41.13-alter-add-column-generated-backfill.sqllogic +566 -0
- package/test/logic/41.14-alter-add-column-subquery-backfill.sqllogic +129 -0
- package/test/logic/41.15-alter-column-default-type-check.sqllogic +178 -0
- package/test/logic/41.16-fk-unenforceable.sqllogic +364 -0
- package/test/logic/41.2-alter-column.sqllogic +382 -0
- package/test/logic/41.2.1-alter-column-retype-deleted-row-memory.sqllogic +32 -0
- package/test/logic/41.2.2-alter-column-retype-index-rebuild.sqllogic +77 -0
- package/test/logic/41.2.3-alter-column-set-not-null-pk-backfill.sqllogic +310 -0
- package/test/logic/41.2.3.1-alter-column-set-not-null-pk-backfill-secondary-index.sqllogic +37 -0
- package/test/logic/41.3-alter-add-column-unique.sqllogic +184 -0
- package/test/logic/41.3-alter-rename-propagation.sqllogic +2352 -0
- package/test/logic/41.3.1-alter-rename-index-propagation.sqllogic +94 -0
- package/test/logic/41.4-alter-add-column-constraints.sqllogic +855 -0
- package/test/logic/41.5-alter-misc.sqllogic +48 -0
- package/test/logic/41.5-cross-schema-foreign-keys.sqllogic +253 -0
- package/test/logic/41.6-alter-drop-rename-constraint.sqllogic +354 -0
- package/test/logic/41.6.1-alter-drop-constraint-index-derived.sqllogic +22 -0
- package/test/logic/41.7-alter-column-collate.sqllogic +105 -0
- package/test/logic/41.7.1-alter-column-collate-unique.sqllogic +45 -0
- package/test/logic/41.7.2-alter-column-collate-unique-store.sqllogic +208 -0
- package/test/logic/41.7.2.1-alter-column-collate-unique-index-store.sqllogic +114 -0
- package/test/logic/41.7.3-alter-column-retype-unique.sqllogic +293 -0
- package/test/logic/41.7.3.1-alter-column-retype-staged-rows-memory.sqllogic +41 -0
- package/test/logic/41.7.3.2-alter-column-retype-unique-index.sqllogic +72 -0
- package/test/logic/41.7.4-alter-column-retype-semantic-memory.sqllogic +445 -0
- package/test/logic/41.7.4.1-alter-column-retype-semantic-index-memory.sqllogic +91 -0
- package/test/logic/41.7.5-alter-column-collate-pk-staged-delete-memory.sqllogic +106 -0
- package/test/logic/41.8-alter-add-constraint-unique-fk.sqllogic +275 -0
- package/test/logic/41.8-alter-savepoint-staged-rows.sqllogic +443 -0
- package/test/logic/41.8.1-alter-rename-savepoint-staged-rows.sqllogic +408 -0
- package/test/logic/41.9-alter-constraint-body-change.sqllogic +180 -0
- package/test/logic/41.9-fk-restrict-batched.sqllogic +290 -0
- package/test/logic/42-committed-snapshot.sqllogic +254 -0
- package/test/logic/42-returning.sqllogic +159 -0
- package/test/logic/42.1-returning-extras.sqllogic +232 -0
- package/test/logic/42.2-returning-stored-row.sqllogic +165 -0
- package/test/logic/43-default-nullability.sqllogic +131 -0
- package/test/logic/43-transition-constraints.sqllogic +341 -0
- package/test/logic/43.1-default-collation.sqllogic +140 -0
- package/test/logic/43.1-notnull-or-conflict.sqllogic +79 -0
- package/test/logic/43.2-deferred-check-new-on-delete.sqllogic +95 -0
- package/test/logic/43.3-nullable-primary-key.sqllogic +587 -0
- package/test/logic/44-determinism-validation.sqllogic +164 -0
- package/test/logic/44-orthogonality.sqllogic +146 -0
- package/test/logic/44.1-nondeterministic-schema.sqllogic +316 -0
- package/test/logic/45-udf-determinism.sqllogic +39 -0
- package/test/logic/46-mutation-context.sqllogic +595 -0
- package/test/logic/47-upsert.sqllogic +255 -0
- package/test/logic/47.1-upsert-conflict-targets.sqllogic +169 -0
- package/test/logic/47.2-replace-and-or-clauses.sqllogic +164 -0
- package/test/logic/47.2.1-pk-replace-secondary-unique.sqllogic +374 -0
- package/test/logic/47.3-engine-or-fail.sqllogic +122 -0
- package/test/logic/47.3-upsert-conflict-target-collation.sqllogic +139 -0
- package/test/logic/47.3.1-upsert-conflict-index-derived-collation.sqllogic +25 -0
- package/test/logic/47.4-upsert-conflict-target-affinity.sqllogic +59 -0
- package/test/logic/47.5-upsert-do-update-constraints.sqllogic +440 -0
- package/test/logic/47.6-upsert-do-update-decomposed.sqllogic +100 -0
- package/test/logic/49-reference-graph.sqllogic +84 -0
- package/test/logic/50-declarative-schema.sqllogic +2550 -0
- package/test/logic/50-metadata-tags.sqllogic +1033 -0
- package/test/logic/50.0.1-metadata-tags-index.sqllogic +141 -0
- package/test/logic/50.1-declare-schema-pk.sqllogic +150 -0
- package/test/logic/50.2-declare-schema-renames.sqllogic +949 -0
- package/test/logic/50.2.1-declare-schema-index-renames.sqllogic +210 -0
- package/test/logic/50.3-declare-schema-duplicate-names.sqllogic +280 -0
- package/test/logic/50.4-declare-schema-apply-restore.sqllogic +192 -0
- package/test/logic/51-lens-foundation.sqllogic +147 -0
- package/test/logic/51-materialized-views.sqllogic +376 -0
- package/test/logic/51.5-materialized-views-coarsened-key.sqllogic +198 -0
- package/test/logic/51.7-maintained-table-attach-detach.sqllogic +468 -0
- package/test/logic/51.8-maintained-table-declared-constraints.sqllogic +440 -0
- package/test/logic/51.85-maintained-table-parent-fk.sqllogic +103 -0
- package/test/logic/51.9-maintained-table-secondary-unique.sqllogic +237 -0
- package/test/logic/51.9.1-maintained-table-partial-unique.sqllogic +36 -0
- package/test/logic/52-lens-overrides.sqllogic +566 -0
- package/test/logic/53-materialized-views-rowtime.sqllogic +1601 -0
- package/test/logic/53-reserved-tags.sqllogic +252 -0
- package/test/logic/53.1-materialized-view-write-through.sqllogic +329 -0
- package/test/logic/53.2-materialized-view-rename-propagation.sqllogic +483 -0
- package/test/logic/53.3-materialized-view-constraint-only-ddl.sqllogic +409 -0
- package/test/logic/53.3.1-materialized-view-index-ddl-irrelevance.sqllogic +29 -0
- package/test/logic/53.4-materialized-view-structural-alter-restore.sqllogic +436 -0
- package/test/logic/54-covering-mv-enforcement.sqllogic +314 -0
- package/test/logic/54.1-covering-mv-partial-enforcement.sqllogic +34 -0
- package/test/logic/55-internal-eviction-reporting.sqllogic +89 -0
- package/test/logic/55-lens-prover.sqllogic +202 -0
- package/test/logic/55.1-eviction-restrict-fk.sqllogic +148 -0
- package/test/logic/55.5-lens-authored-inverse.sqllogic +1468 -0
- package/test/logic/80-grow-retrieve-pass.sqllogic +79 -0
- package/test/logic/81-quickpick.sqllogic +24 -0
- package/test/logic/82-bloom-join.sqllogic +185 -0
- package/test/logic/83-merge-join.sqllogic +280 -0
- package/test/logic/84-asof-scan.sqllogic +238 -0
- package/test/logic/84-key-cardinality.sqllogic +50 -0
- package/test/logic/85-relational-const-folding.sqllogic +51 -0
- package/test/logic/86-scalar-cse.sqllogic +42 -0
- package/test/logic/90-error_paths.sqllogic +114 -0
- package/test/logic/90.1-parse-errors.sqllogic +77 -0
- package/test/logic/90.2-alter-table-errors.sqllogic +53 -0
- package/test/logic/90.2.1-alter-extra-errors.sqllogic +51 -0
- package/test/logic/90.3-expression-errors.sqllogic +43 -0
- package/test/logic/90.4-dml-errors.sqllogic +47 -0
- package/test/logic/90.5-unsupported-join-types.sqllogic +37 -0
- package/test/logic/90.5.1-right-full-join-read.sqllogic +157 -0
- package/test/logic/90.6-select-error-paths.sqllogic +57 -0
- package/test/logic/91-merge-join-edge-cases.sqllogic +159 -0
- package/test/logic/92-hash-aggregate-edge-cases.sqllogic +139 -0
- package/test/logic/93-ddl-view-edge-cases.sqllogic +104 -0
- package/test/logic/93.1-view-error-paths.sqllogic +74 -0
- package/test/logic/93.2-view-mutation-pending.sqllogic +108 -0
- package/test/logic/93.3-view-mutation-or-clause.sqllogic +60 -0
- package/test/logic/93.4-view-mutation.sqllogic +4881 -0
- package/test/logic/93.4.1-view-mutation-partial-unique-cardinality.sqllogic +31 -0
- package/test/logic/93.5-authored-inverse.sqllogic +415 -0
- package/test/logic/93.6-set-op-flagless-write.sqllogic +862 -0
- package/test/logic/94-tvf-edge-cases.sqllogic +58 -0
- package/test/logic/94.1-limit-offset-edge-cases.sqllogic +109 -0
- package/test/logic/94.2-limit-offset-extras.sqllogic +98 -0
- package/test/logic/95-assertions.sqllogic +1417 -0
- package/test/logic/96-subquery-edge-cases.sqllogic +276 -0
- package/test/logic/97-json-function-edge-cases.sqllogic +633 -0
- package/test/logic/97.1-json-blob-and-special-values.sqllogic +92 -0
- package/test/logic/98-temporal-edge-cases.sqllogic +515 -0
- package/test/logic/99-conversion-edge-cases.sqllogic +325 -0
- package/test/logic/99.0.1-schema-index-listing.sqllogic +21 -0
- package/test/logic/99.1-cast-syntax-extras.sqllogic +167 -0
- package/test/logic/drop-unique-index.sqllogic +88 -0
- package/test/logic/pushdown-test.sqllogic +36 -0
|
@@ -0,0 +1,595 @@
|
|
|
1
|
+
-- Mutation Context Tests
|
|
2
|
+
-- Tests for table-level mutation context variables used in defaults and constraints
|
|
3
|
+
-- Primary use case: application-specific security, rights, signatures, and audit
|
|
4
|
+
|
|
5
|
+
-- Test 1: Use mutation context in default values
|
|
6
|
+
CREATE TABLE products (
|
|
7
|
+
id INTEGER PRIMARY KEY,
|
|
8
|
+
base_price INTEGER,
|
|
9
|
+
final_price INTEGER DEFAULT base_price + markup
|
|
10
|
+
) USING memory
|
|
11
|
+
WITH CONTEXT (
|
|
12
|
+
markup INTEGER
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
INSERT INTO products (id, base_price)
|
|
16
|
+
WITH CONTEXT markup = 50
|
|
17
|
+
VALUES (1, 100);
|
|
18
|
+
|
|
19
|
+
SELECT id, base_price, final_price FROM products
|
|
20
|
+
→ [{"id":1,"base_price":100,"final_price":150}]
|
|
21
|
+
|
|
22
|
+
-- Test 2: Use mutation context in CHECK constraints
|
|
23
|
+
CREATE TABLE stock (
|
|
24
|
+
sku TEXT PRIMARY KEY,
|
|
25
|
+
quantity INTEGER,
|
|
26
|
+
CONSTRAINT qty_check CHECK (NEW.quantity >= min_qty)
|
|
27
|
+
) USING memory
|
|
28
|
+
WITH CONTEXT (
|
|
29
|
+
min_qty INTEGER
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
-- Should succeed with quantity >= min_qty
|
|
33
|
+
INSERT INTO stock (sku, quantity)
|
|
34
|
+
WITH CONTEXT min_qty = 10
|
|
35
|
+
VALUES ('SKU001', 20);
|
|
36
|
+
|
|
37
|
+
SELECT sku, quantity FROM stock
|
|
38
|
+
→ [{"sku":"SKU001","quantity":20}]
|
|
39
|
+
|
|
40
|
+
-- Should fail with quantity < min_qty
|
|
41
|
+
INSERT INTO stock (sku, quantity)
|
|
42
|
+
WITH CONTEXT min_qty = 50
|
|
43
|
+
VALUES ('SKU002', 30);
|
|
44
|
+
-- error: CHECK constraint failed
|
|
45
|
+
|
|
46
|
+
-- Test 3: Qualified context.varName references
|
|
47
|
+
CREATE TABLE items (
|
|
48
|
+
id INTEGER PRIMARY KEY,
|
|
49
|
+
value INTEGER,
|
|
50
|
+
CONSTRAINT value_check CHECK (NEW.value >= context.threshold)
|
|
51
|
+
) USING memory
|
|
52
|
+
WITH CONTEXT (
|
|
53
|
+
threshold INTEGER
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
INSERT INTO items (id, value)
|
|
57
|
+
WITH CONTEXT threshold = 100
|
|
58
|
+
VALUES (1, 150);
|
|
59
|
+
|
|
60
|
+
SELECT id, value FROM items
|
|
61
|
+
→ [{"id":1,"value":150}]
|
|
62
|
+
|
|
63
|
+
-- Test 4: UPDATE with mutation context
|
|
64
|
+
CREATE TABLE prices (
|
|
65
|
+
product_id INTEGER PRIMARY KEY,
|
|
66
|
+
price INTEGER,
|
|
67
|
+
CONSTRAINT price_check CHECK (NEW.price >= min_price)
|
|
68
|
+
) USING memory
|
|
69
|
+
WITH CONTEXT (
|
|
70
|
+
min_price INTEGER
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
INSERT INTO prices
|
|
74
|
+
WITH CONTEXT min_price = 0
|
|
75
|
+
VALUES (1, 100);
|
|
76
|
+
|
|
77
|
+
UPDATE prices
|
|
78
|
+
WITH CONTEXT min_price = 50
|
|
79
|
+
SET price = 75
|
|
80
|
+
WHERE product_id = 1;
|
|
81
|
+
|
|
82
|
+
SELECT price FROM prices WHERE product_id = 1
|
|
83
|
+
→ [{"price":75}]
|
|
84
|
+
|
|
85
|
+
-- Update with invalid context should fail
|
|
86
|
+
UPDATE prices
|
|
87
|
+
WITH CONTEXT min_price = 100
|
|
88
|
+
SET price = 80
|
|
89
|
+
WHERE product_id = 1;
|
|
90
|
+
-- error: CHECK constraint failed
|
|
91
|
+
|
|
92
|
+
-- Test 5: DELETE with mutation context
|
|
93
|
+
CREATE TABLE audit (
|
|
94
|
+
sku TEXT PRIMARY KEY,
|
|
95
|
+
quantity INTEGER,
|
|
96
|
+
CONSTRAINT delete_check CHECK ON DELETE (allow_delete = 1)
|
|
97
|
+
) USING memory
|
|
98
|
+
WITH CONTEXT (
|
|
99
|
+
allow_delete INTEGER
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
INSERT INTO audit
|
|
103
|
+
WITH CONTEXT allow_delete = 1
|
|
104
|
+
VALUES ('A', 10), ('B', 20);
|
|
105
|
+
|
|
106
|
+
DELETE FROM audit
|
|
107
|
+
WITH CONTEXT allow_delete = 1
|
|
108
|
+
WHERE sku = 'A';
|
|
109
|
+
|
|
110
|
+
SELECT sku FROM audit
|
|
111
|
+
→ [{"sku":"B"}]
|
|
112
|
+
|
|
113
|
+
-- Delete with allow_delete = 0 should fail
|
|
114
|
+
DELETE FROM audit
|
|
115
|
+
WITH CONTEXT allow_delete = 0
|
|
116
|
+
WHERE sku = 'B';
|
|
117
|
+
-- error: CHECK constraint failed
|
|
118
|
+
|
|
119
|
+
-- Test 6: Multiple context variables
|
|
120
|
+
CREATE TABLE orders (
|
|
121
|
+
id INTEGER PRIMARY KEY,
|
|
122
|
+
amount INTEGER DEFAULT base + tax + shipping
|
|
123
|
+
) USING memory
|
|
124
|
+
WITH CONTEXT (
|
|
125
|
+
base INTEGER,
|
|
126
|
+
tax INTEGER,
|
|
127
|
+
shipping INTEGER
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
INSERT INTO orders (id)
|
|
131
|
+
WITH CONTEXT base = 100, tax = 15, shipping = 5
|
|
132
|
+
VALUES (1);
|
|
133
|
+
|
|
134
|
+
SELECT amount FROM orders WHERE id = 1
|
|
135
|
+
→ [{"amount":120}]
|
|
136
|
+
|
|
137
|
+
-- Test 7: NULL context variables
|
|
138
|
+
CREATE TABLE config (
|
|
139
|
+
id INTEGER PRIMARY KEY,
|
|
140
|
+
max_val INTEGER DEFAULT coalesce(limit_val, 999)
|
|
141
|
+
) USING memory
|
|
142
|
+
WITH CONTEXT (
|
|
143
|
+
limit_val INTEGER NULL
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
INSERT INTO config (id)
|
|
147
|
+
WITH CONTEXT limit_val = NULL
|
|
148
|
+
VALUES (1);
|
|
149
|
+
|
|
150
|
+
SELECT max_val FROM config WHERE id = 1
|
|
151
|
+
→ [{"max_val":999}]
|
|
152
|
+
|
|
153
|
+
-- Test 8: RETURNING with mutation context
|
|
154
|
+
CREATE TABLE computed (
|
|
155
|
+
id INTEGER PRIMARY KEY,
|
|
156
|
+
result INTEGER DEFAULT base * multiplier
|
|
157
|
+
) USING memory
|
|
158
|
+
WITH CONTEXT (
|
|
159
|
+
base INTEGER,
|
|
160
|
+
multiplier INTEGER
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
INSERT INTO computed (id)
|
|
164
|
+
WITH CONTEXT base = 10, multiplier = 5
|
|
165
|
+
VALUES (1)
|
|
166
|
+
RETURNING id, result
|
|
167
|
+
→ [{"id":1,"result":50}]
|
|
168
|
+
|
|
169
|
+
-- Test 9: Context variable shadowing column names
|
|
170
|
+
CREATE TABLE shadowing (
|
|
171
|
+
id INTEGER PRIMARY KEY,
|
|
172
|
+
value TEXT NULL,
|
|
173
|
+
label TEXT DEFAULT value
|
|
174
|
+
) USING memory
|
|
175
|
+
WITH CONTEXT (
|
|
176
|
+
value TEXT
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
INSERT INTO shadowing (id)
|
|
180
|
+
WITH CONTEXT value = 'from_context'
|
|
181
|
+
VALUES (1);
|
|
182
|
+
|
|
183
|
+
SELECT label FROM shadowing WHERE id = 1
|
|
184
|
+
→ [{"label":"from_context"}]
|
|
185
|
+
|
|
186
|
+
-- Test 10: Deferred constraints with mutation context
|
|
187
|
+
CREATE TABLE deferred_test (
|
|
188
|
+
id INTEGER PRIMARY KEY,
|
|
189
|
+
stock INTEGER,
|
|
190
|
+
CONSTRAINT stock_check CHECK (
|
|
191
|
+
NEW.stock >= min_stock OR
|
|
192
|
+
EXISTS (SELECT 1 FROM deferred_test WHERE id = NEW.id AND stock > 0)
|
|
193
|
+
)
|
|
194
|
+
) USING memory
|
|
195
|
+
WITH CONTEXT (
|
|
196
|
+
min_stock INTEGER
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
BEGIN;
|
|
200
|
+
|
|
201
|
+
INSERT INTO deferred_test (id, stock)
|
|
202
|
+
WITH CONTEXT min_stock = 10
|
|
203
|
+
VALUES (1, 15);
|
|
204
|
+
|
|
205
|
+
COMMIT;
|
|
206
|
+
|
|
207
|
+
SELECT stock FROM deferred_test WHERE id = 1
|
|
208
|
+
→ [{"stock":15}]
|
|
209
|
+
|
|
210
|
+
-- Test 11: new.<column> reads a supplied sibling alongside a context variable
|
|
211
|
+
CREATE TABLE invoice (
|
|
212
|
+
id INTEGER PRIMARY KEY,
|
|
213
|
+
subtotal INTEGER,
|
|
214
|
+
total INTEGER DEFAULT (new.subtotal + tax)
|
|
215
|
+
) USING memory
|
|
216
|
+
WITH CONTEXT (
|
|
217
|
+
tax INTEGER
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
INSERT INTO invoice (id, subtotal)
|
|
221
|
+
WITH CONTEXT tax = 7
|
|
222
|
+
VALUES (1, 100);
|
|
223
|
+
|
|
224
|
+
SELECT total FROM invoice WHERE id = 1
|
|
225
|
+
→ [{"total":107}]
|
|
226
|
+
|
|
227
|
+
-- Test 12: bare-vs-new precedence when the colliding column IS supplied.
|
|
228
|
+
-- A context variable and a column share the name `amount`. When `amount` is
|
|
229
|
+
-- supplied by the INSERT, a bare `amount` reference still resolves to the
|
|
230
|
+
-- context variable (context shadows the column), while `new.amount` resolves to
|
|
231
|
+
-- the supplied column value. No "symbol already exists" collision is raised.
|
|
232
|
+
CREATE TABLE collide (
|
|
233
|
+
id INTEGER PRIMARY KEY,
|
|
234
|
+
amount INTEGER NULL,
|
|
235
|
+
bare_label INTEGER DEFAULT amount,
|
|
236
|
+
qual_label INTEGER DEFAULT (new.amount)
|
|
237
|
+
) USING memory
|
|
238
|
+
WITH CONTEXT (
|
|
239
|
+
amount INTEGER
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
INSERT INTO collide (id, amount)
|
|
243
|
+
WITH CONTEXT amount = 999
|
|
244
|
+
VALUES (1, 100);
|
|
245
|
+
|
|
246
|
+
SELECT bare_label, qual_label FROM collide WHERE id = 1
|
|
247
|
+
→ [{"bare_label":999,"qual_label":100}]
|
|
248
|
+
|
|
249
|
+
-- Test 13: ALTER COLUMN SET DEFAULT coexists with a context variable. The default
|
|
250
|
+
-- is installed via ALTER (not CREATE) yet resolves `new.<col>` (a supplied sibling)
|
|
251
|
+
-- alongside a context variable at INSERT time — mirroring Test 11.
|
|
252
|
+
CREATE TABLE invoice_alt (
|
|
253
|
+
id INTEGER PRIMARY KEY,
|
|
254
|
+
subtotal INTEGER,
|
|
255
|
+
total INTEGER
|
|
256
|
+
) USING memory
|
|
257
|
+
WITH CONTEXT (
|
|
258
|
+
tax INTEGER
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
ALTER TABLE invoice_alt ALTER COLUMN total SET DEFAULT (new.subtotal + tax);
|
|
262
|
+
|
|
263
|
+
INSERT INTO invoice_alt (id, subtotal)
|
|
264
|
+
WITH CONTEXT tax = 7
|
|
265
|
+
VALUES (1, 100);
|
|
266
|
+
|
|
267
|
+
SELECT total FROM invoice_alt WHERE id = 1
|
|
268
|
+
→ [{"total":107}]
|
|
269
|
+
|
|
270
|
+
-- Test 14: through the shared-surrogate envelope — a member-table column default
|
|
271
|
+
-- reads a supplied sibling via `new.<col>` alongside a per-statement context
|
|
272
|
+
-- variable. The shared key is minted once from the anchor's allocator default; the
|
|
273
|
+
-- member's `total` default combines `new.amount` (supplied) with `tax` (context).
|
|
274
|
+
CREATE TABLE ec_core (
|
|
275
|
+
rid INTEGER PRIMARY KEY DEFAULT (coalesce((SELECT max(rid) FROM ec_core), 0) + mutation_ordinal()),
|
|
276
|
+
name TEXT
|
|
277
|
+
) USING memory;
|
|
278
|
+
CREATE TABLE ec_line (
|
|
279
|
+
rid INTEGER PRIMARY KEY,
|
|
280
|
+
amount INTEGER,
|
|
281
|
+
total INTEGER DEFAULT (new.amount + tax)
|
|
282
|
+
) USING memory
|
|
283
|
+
WITH CONTEXT (
|
|
284
|
+
tax INTEGER
|
|
285
|
+
);
|
|
286
|
+
CREATE VIEW ec_v AS SELECT c.name AS name, l.amount AS amount
|
|
287
|
+
FROM ec_core c JOIN ec_line l ON l.rid = c.rid;
|
|
288
|
+
|
|
289
|
+
INSERT INTO ec_v WITH CONTEXT tax = 5 VALUES ('Ada', 100), ('Lin', 200);
|
|
290
|
+
|
|
291
|
+
SELECT rid, amount, total FROM ec_line ORDER BY rid
|
|
292
|
+
→ [{"rid":1,"amount":100,"total":105},{"rid":2,"amount":200,"total":205}]
|
|
293
|
+
|
|
294
|
+
-- Test 15: a subquery as a WITH CONTEXT value (optimizer must see it as a child).
|
|
295
|
+
-- `DmlExecutorNode` and `ConstraintCheckNode` both expose their mutation-context
|
|
296
|
+
-- value expressions as getChildren() so a subquery there gets rewritten like any
|
|
297
|
+
-- other plan node. See bug-dml-side-expressions-invisible-to-optimizer.
|
|
298
|
+
|
|
299
|
+
CREATE TABLE ctx_src (id INTEGER PRIMARY KEY, v TEXT);
|
|
300
|
+
INSERT INTO ctx_src VALUES (1, 'a'), (2, 'b'), (3, 'c');
|
|
301
|
+
|
|
302
|
+
-- Each op's context value feeds a CHECK constraint, mirroring Tests 2/4/5 above
|
|
303
|
+
-- but with a subquery in place of a literal — proving the rewritten value reaches
|
|
304
|
+
-- `ConstraintCheckNode` (not just the DML executor) for INSERT, UPDATE and DELETE.
|
|
305
|
+
|
|
306
|
+
CREATE TABLE ctx_insert (
|
|
307
|
+
id INTEGER PRIMARY KEY,
|
|
308
|
+
CONSTRAINT gate_check CHECK (NEW.id <= who)
|
|
309
|
+
) USING memory
|
|
310
|
+
WITH CONTEXT (
|
|
311
|
+
who INTEGER
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
-- passes: subquery count is 3, id is 1
|
|
315
|
+
INSERT INTO ctx_insert (id)
|
|
316
|
+
WITH CONTEXT who = (SELECT COUNT(*) FROM ctx_src)
|
|
317
|
+
VALUES (1);
|
|
318
|
+
|
|
319
|
+
SELECT id FROM ctx_insert
|
|
320
|
+
→ [{"id":1}]
|
|
321
|
+
|
|
322
|
+
-- fails: subquery count is 1, id is 2
|
|
323
|
+
INSERT INTO ctx_insert (id)
|
|
324
|
+
WITH CONTEXT who = (SELECT COUNT(*) FROM ctx_src WHERE id = 1)
|
|
325
|
+
VALUES (2);
|
|
326
|
+
-- error: CHECK constraint failed
|
|
327
|
+
|
|
328
|
+
DROP TABLE ctx_insert;
|
|
329
|
+
|
|
330
|
+
CREATE TABLE ctx_update (
|
|
331
|
+
id INTEGER PRIMARY KEY,
|
|
332
|
+
val INTEGER,
|
|
333
|
+
CONSTRAINT gate_check CHECK (NEW.val <= who)
|
|
334
|
+
) USING memory
|
|
335
|
+
WITH CONTEXT (
|
|
336
|
+
who INTEGER
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
INSERT INTO ctx_update WITH CONTEXT who = 999 VALUES (1, 0);
|
|
340
|
+
|
|
341
|
+
-- passes: subquery count is 3, val is 2
|
|
342
|
+
UPDATE ctx_update
|
|
343
|
+
WITH CONTEXT who = (SELECT COUNT(*) FROM ctx_src)
|
|
344
|
+
SET val = 2
|
|
345
|
+
WHERE id = 1;
|
|
346
|
+
|
|
347
|
+
SELECT val FROM ctx_update WHERE id = 1
|
|
348
|
+
→ [{"val":2}]
|
|
349
|
+
|
|
350
|
+
-- fails: subquery count is 1, val is 2
|
|
351
|
+
UPDATE ctx_update
|
|
352
|
+
WITH CONTEXT who = (SELECT COUNT(*) FROM ctx_src WHERE id = 1)
|
|
353
|
+
SET val = 2
|
|
354
|
+
WHERE id = 1;
|
|
355
|
+
-- error: CHECK constraint failed
|
|
356
|
+
|
|
357
|
+
DROP TABLE ctx_update;
|
|
358
|
+
|
|
359
|
+
CREATE TABLE ctx_delete (
|
|
360
|
+
id INTEGER PRIMARY KEY,
|
|
361
|
+
CONSTRAINT delete_check CHECK ON DELETE (who >= 3)
|
|
362
|
+
) USING memory
|
|
363
|
+
WITH CONTEXT (
|
|
364
|
+
who INTEGER
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
INSERT INTO ctx_delete WITH CONTEXT who = 999 VALUES (1), (2);
|
|
368
|
+
|
|
369
|
+
-- fails: subquery count is 1
|
|
370
|
+
DELETE FROM ctx_delete
|
|
371
|
+
WITH CONTEXT who = (SELECT COUNT(*) FROM ctx_src WHERE id = 1)
|
|
372
|
+
WHERE id = 1;
|
|
373
|
+
-- error: CHECK constraint failed
|
|
374
|
+
|
|
375
|
+
-- passes: subquery count is 3
|
|
376
|
+
DELETE FROM ctx_delete
|
|
377
|
+
WITH CONTEXT who = (SELECT COUNT(*) FROM ctx_src)
|
|
378
|
+
WHERE id = 1;
|
|
379
|
+
|
|
380
|
+
SELECT id FROM ctx_delete
|
|
381
|
+
→ [{"id":2}]
|
|
382
|
+
|
|
383
|
+
DROP TABLE ctx_delete;
|
|
384
|
+
DROP TABLE ctx_src;
|
|
385
|
+
|
|
386
|
+
-- Test 16: omitting the envelope on a table whose CHECK reads a NOT NULL context
|
|
387
|
+
-- variable reports the missing STATEMENT argument, naming both table and variable —
|
|
388
|
+
-- not "context.<var> isn't a column", which pointed the reader at the schema.
|
|
389
|
+
CREATE TABLE revocation (
|
|
390
|
+
stamp_id TEXT PRIMARY KEY,
|
|
391
|
+
reissued_at INTEGER NULL,
|
|
392
|
+
CONSTRAINT authorized_reissue CHECK (context.owner_key = 'k')
|
|
393
|
+
) USING memory
|
|
394
|
+
WITH CONTEXT (
|
|
395
|
+
owner_key TEXT,
|
|
396
|
+
signature TEXT NULL
|
|
397
|
+
);
|
|
398
|
+
|
|
399
|
+
INSERT INTO revocation (stamp_id) VALUES ('a');
|
|
400
|
+
-- error: table 'main.revocation' requires mutation context variable 'owner_key'
|
|
401
|
+
|
|
402
|
+
-- Test 17: supplying an envelope that omits one NOT NULL variable is the same
|
|
403
|
+
-- diagnosis, not an internal error.
|
|
404
|
+
INSERT INTO revocation (stamp_id) WITH CONTEXT signature = 'x' VALUES ('a');
|
|
405
|
+
-- error: table 'main.revocation' requires mutation context variable 'owner_key'
|
|
406
|
+
|
|
407
|
+
UPDATE revocation WITH CONTEXT signature = 'x' SET reissued_at = 1;
|
|
408
|
+
-- error: table 'main.revocation' requires mutation context variable 'owner_key'
|
|
409
|
+
|
|
410
|
+
-- The NULL-marked `signature` may be omitted entirely.
|
|
411
|
+
INSERT INTO revocation (stamp_id) WITH CONTEXT owner_key = 'k' VALUES ('a');
|
|
412
|
+
|
|
413
|
+
SELECT stamp_id, reissued_at FROM revocation
|
|
414
|
+
→ [{"stamp_id":"a","reissued_at":null}]
|
|
415
|
+
|
|
416
|
+
-- Test 18: a name the table does not declare is ignored, not rejected. View
|
|
417
|
+
-- decomposition forwards one envelope verbatim to every member statement, so a member
|
|
418
|
+
-- routinely receives values for variables it never declared.
|
|
419
|
+
INSERT INTO revocation (stamp_id) WITH CONTEXT owner_key = 'k', bogus = 1 VALUES ('b');
|
|
420
|
+
|
|
421
|
+
SELECT stamp_id FROM revocation ORDER BY stamp_id
|
|
422
|
+
→ [{"stamp_id":"a"},{"stamp_id":"b"}]
|
|
423
|
+
|
|
424
|
+
-- Test 19: an omitted NULL-marked variable reads as NULL rather than erroring, so a
|
|
425
|
+
-- CHECK comparing against it behaves like any NULL comparison (unknown ⇒ passes),
|
|
426
|
+
-- and one written to reject NULL fails as a CHECK — never as a missing argument.
|
|
427
|
+
CREATE TABLE floor_guard (
|
|
428
|
+
id INTEGER PRIMARY KEY,
|
|
429
|
+
v INTEGER NULL,
|
|
430
|
+
CONSTRAINT unknown_passes CHECK (v >= floor_v)
|
|
431
|
+
) USING memory
|
|
432
|
+
WITH CONTEXT (
|
|
433
|
+
floor_v INTEGER NULL
|
|
434
|
+
);
|
|
435
|
+
|
|
436
|
+
INSERT INTO floor_guard (id, v) VALUES (1, 5);
|
|
437
|
+
|
|
438
|
+
SELECT id, v FROM floor_guard
|
|
439
|
+
→ [{"id":1,"v":5}]
|
|
440
|
+
|
|
441
|
+
CREATE TABLE floor_strict (
|
|
442
|
+
id INTEGER PRIMARY KEY,
|
|
443
|
+
v INTEGER NULL,
|
|
444
|
+
CONSTRAINT null_rejected CHECK (coalesce(v >= floor_v, 0))
|
|
445
|
+
) USING memory
|
|
446
|
+
WITH CONTEXT (
|
|
447
|
+
floor_v INTEGER NULL
|
|
448
|
+
);
|
|
449
|
+
|
|
450
|
+
INSERT INTO floor_strict (id, v) VALUES (1, 5);
|
|
451
|
+
-- error: CHECK constraint failed
|
|
452
|
+
|
|
453
|
+
INSERT INTO floor_strict (id, v) WITH CONTEXT floor_v = 1 VALUES (1, 5);
|
|
454
|
+
|
|
455
|
+
SELECT id, v FROM floor_strict
|
|
456
|
+
→ [{"id":1,"v":5}]
|
|
457
|
+
|
|
458
|
+
-- Test 20: a declared variable that no default or constraint reads never makes the
|
|
459
|
+
-- envelope mandatory — the error is raised where the variable is REFERENCED, not
|
|
460
|
+
-- where the symbols are registered. Regression guard for envelope-less writes.
|
|
461
|
+
CREATE TABLE unread_ctx (
|
|
462
|
+
id INTEGER PRIMARY KEY
|
|
463
|
+
) USING memory
|
|
464
|
+
WITH CONTEXT (
|
|
465
|
+
never_read TEXT
|
|
466
|
+
);
|
|
467
|
+
|
|
468
|
+
INSERT INTO unread_ctx VALUES (1);
|
|
469
|
+
|
|
470
|
+
SELECT id FROM unread_ctx
|
|
471
|
+
→ [{"id":1}]
|
|
472
|
+
|
|
473
|
+
-- Likewise for an op the constraint does not cover: `revocation`'s CHECK is
|
|
474
|
+
-- INSERT/UPDATE-scoped, so a DELETE reads no context variable and needs no envelope.
|
|
475
|
+
DELETE FROM revocation WHERE stamp_id = 'b';
|
|
476
|
+
|
|
477
|
+
SELECT stamp_id FROM revocation
|
|
478
|
+
→ [{"stamp_id":"a"}]
|
|
479
|
+
|
|
480
|
+
-- Test 21: a write mediated by a view reports the MEMBER table that declares the
|
|
481
|
+
-- variable, not the view the statement named.
|
|
482
|
+
CREATE TABLE mv_core (
|
|
483
|
+
rid INTEGER PRIMARY KEY DEFAULT (coalesce((SELECT max(rid) FROM mv_core), 0) + mutation_ordinal()),
|
|
484
|
+
name TEXT
|
|
485
|
+
) USING memory;
|
|
486
|
+
CREATE TABLE mv_line (
|
|
487
|
+
rid INTEGER PRIMARY KEY,
|
|
488
|
+
amount INTEGER,
|
|
489
|
+
CONSTRAINT cap_check CHECK (amount <= cap)
|
|
490
|
+
) USING memory
|
|
491
|
+
WITH CONTEXT (
|
|
492
|
+
cap INTEGER
|
|
493
|
+
);
|
|
494
|
+
CREATE VIEW mv_v AS SELECT c.name AS name, l.amount AS amount
|
|
495
|
+
FROM mv_core c JOIN mv_line l ON l.rid = c.rid;
|
|
496
|
+
|
|
497
|
+
INSERT INTO mv_v VALUES ('Ada', 10);
|
|
498
|
+
-- error: table 'main.mv_line' requires mutation context variable 'cap'
|
|
499
|
+
|
|
500
|
+
INSERT INTO mv_v WITH CONTEXT cap = 100 VALUES ('Lin', 10);
|
|
501
|
+
|
|
502
|
+
SELECT rid, amount FROM mv_line
|
|
503
|
+
→ [{"rid":1,"amount":10}]
|
|
504
|
+
|
|
505
|
+
-- Test 22: BEHAVIOR CHANGE — context variables are now registered for a write that
|
|
506
|
+
-- supplies no envelope, so a bare reference that collides with a column name resolves
|
|
507
|
+
-- to the (unsupplied, hence NULL) context variable, where it used to resolve to the
|
|
508
|
+
-- column. Precedence is the documented one; only the envelope-less case moved.
|
|
509
|
+
CREATE TABLE shadow_null (
|
|
510
|
+
id INTEGER PRIMARY KEY,
|
|
511
|
+
value TEXT NULL,
|
|
512
|
+
bare_label TEXT NULL DEFAULT value,
|
|
513
|
+
qual_label TEXT NULL DEFAULT (new.value)
|
|
514
|
+
) USING memory
|
|
515
|
+
WITH CONTEXT (
|
|
516
|
+
value TEXT NULL
|
|
517
|
+
);
|
|
518
|
+
|
|
519
|
+
INSERT INTO shadow_null (id, value) VALUES (1, 'col');
|
|
520
|
+
INSERT INTO shadow_null (id, value) WITH CONTEXT value = 'ctx' VALUES (2, 'col');
|
|
521
|
+
|
|
522
|
+
SELECT id, bare_label, qual_label FROM shadow_null ORDER BY id
|
|
523
|
+
→ [{"id":1,"bare_label":null,"qual_label":"col"},{"id":2,"bare_label":"ctx","qual_label":"col"}]
|
|
524
|
+
|
|
525
|
+
-- Test 23: a deferred CHECK captures context at write time and evaluates at COMMIT;
|
|
526
|
+
-- an omitted NULL-marked variable must survive that capture AS NULL, not vanish (which
|
|
527
|
+
-- would misalign the captured context row against its descriptor).
|
|
528
|
+
CREATE TABLE deferred_null_ctx (
|
|
529
|
+
id INTEGER PRIMARY KEY,
|
|
530
|
+
stock INTEGER,
|
|
531
|
+
CONSTRAINT stock_check CHECK (
|
|
532
|
+
coalesce(stock >= min_stock, 1) AND
|
|
533
|
+
EXISTS (SELECT 1 FROM deferred_null_ctx WHERE id = NEW.id)
|
|
534
|
+
)
|
|
535
|
+
) USING memory
|
|
536
|
+
WITH CONTEXT (
|
|
537
|
+
min_stock INTEGER NULL
|
|
538
|
+
);
|
|
539
|
+
|
|
540
|
+
BEGIN;
|
|
541
|
+
|
|
542
|
+
INSERT INTO deferred_null_ctx (id, stock) VALUES (1, 15);
|
|
543
|
+
|
|
544
|
+
COMMIT;
|
|
545
|
+
|
|
546
|
+
SELECT stock FROM deferred_null_ctx WHERE id = 1
|
|
547
|
+
→ [{"stock":15}]
|
|
548
|
+
|
|
549
|
+
-- The same deferred constraint still sees a supplied value.
|
|
550
|
+
BEGIN;
|
|
551
|
+
|
|
552
|
+
INSERT INTO deferred_null_ctx (id, stock) WITH CONTEXT min_stock = 99 VALUES (2, 15);
|
|
553
|
+
|
|
554
|
+
COMMIT;
|
|
555
|
+
-- error: CHECK constraint failed
|
|
556
|
+
|
|
557
|
+
-- Test 24: a NOT NULL column whose DEFAULT reads an omitted NULL-marked variable
|
|
558
|
+
-- yields NULL and then hits the ordinary NOT NULL column check — not a context error.
|
|
559
|
+
CREATE TABLE stamped (
|
|
560
|
+
id INTEGER PRIMARY KEY,
|
|
561
|
+
who TEXT NOT NULL DEFAULT stamp
|
|
562
|
+
) USING memory
|
|
563
|
+
WITH CONTEXT (
|
|
564
|
+
stamp TEXT NULL
|
|
565
|
+
);
|
|
566
|
+
|
|
567
|
+
INSERT INTO stamped (id) VALUES (1);
|
|
568
|
+
-- error: NOT NULL constraint failed: stamped.who
|
|
569
|
+
|
|
570
|
+
INSERT INTO stamped (id) WITH CONTEXT stamp = 'me' VALUES (2);
|
|
571
|
+
|
|
572
|
+
SELECT id, who FROM stamped
|
|
573
|
+
→ [{"id":2,"who":"me"}]
|
|
574
|
+
|
|
575
|
+
-- Test 25: the UPSERT `do update` arm re-plans the table's UPDATE-scoped constraints,
|
|
576
|
+
-- so the same rules hold there.
|
|
577
|
+
CREATE TABLE upsert_ctx (
|
|
578
|
+
id INTEGER PRIMARY KEY,
|
|
579
|
+
v INTEGER,
|
|
580
|
+
CONSTRAINT cap_check CHECK (v <= cap)
|
|
581
|
+
) USING memory
|
|
582
|
+
WITH CONTEXT (
|
|
583
|
+
cap INTEGER
|
|
584
|
+
);
|
|
585
|
+
|
|
586
|
+
INSERT INTO upsert_ctx WITH CONTEXT cap = 100 VALUES (1, 1);
|
|
587
|
+
|
|
588
|
+
INSERT INTO upsert_ctx VALUES (1, 2) ON CONFLICT (id) DO UPDATE SET v = 2;
|
|
589
|
+
-- error: table 'main.upsert_ctx' requires mutation context variable 'cap'
|
|
590
|
+
|
|
591
|
+
INSERT INTO upsert_ctx WITH CONTEXT cap = 100 VALUES (1, 2) ON CONFLICT (id) DO UPDATE SET v = 2;
|
|
592
|
+
|
|
593
|
+
SELECT id, v FROM upsert_ctx
|
|
594
|
+
→ [{"id":1,"v":2}]
|
|
595
|
+
|