Row-level SQL expressions -- CHECK constraints, domain checks, ON CONFLICT ... WHERE -- evaluated by the SELECT translator, not by a second interpreter.
The expression is deparsed with every column reference replaced by a
typed parameter, CAST($n AS <declared type>), and run as the one-row
SELECT (<expr>) with the row's values bound. Every operator,
function, LIKE, regex, IS DISTINCT FROM and type rule is therefore the
one SELECT uses. The interpreter this replaces answered 'satisfied'
for any shape it did not know and compared only numbers with < and >,
so CHECK (name > 'm') or CHECK (s LIKE 'a%') accepted any row.
Errors propagate with their SQLSTATE, as they do in PostgreSQL.
Row-level SQL expressions -- CHECK constraints, domain checks, ON CONFLICT ... WHERE -- evaluated by the SELECT translator, not by a second interpreter. The expression is deparsed with every column reference replaced by a typed parameter, `CAST($n AS <declared type>)`, and run as the one-row `SELECT (<expr>)` with the row's values bound. Every operator, function, LIKE, regex, IS DISTINCT FROM and type rule is therefore the one SELECT uses. The interpreter this replaces answered 'satisfied' for any shape it did not know and compared only numbers with < and >, so `CHECK (name > 'm')` or `CHECK (s LIKE 'a%')` accepted any row. Errors propagate with their SQLSTATE, as they do in PostgreSQL.
(check-fn db)The CHECK evaluator constraint validation takes: (fn [ast row ns schema
& [column-types]]) over db.
The CHECK evaluator constraint validation takes: (fn [ast row ns schema & [column-types]]) over `db`.
(check-result ast row ns schema db)(check-result ast row ns schema db column-types)true, false or nil (unknown) for the CHECK expression ast over row.
Only false is a violation: CHECK passes on NULL, unlike WHERE.
true, false or nil (unknown) for the CHECK expression `ast` over `row`. Only false is a violation: CHECK passes on NULL, unlike WHERE.
(eval-expression ast row ns schema db)(eval-expression ast row ns schema db column-types)Value of the SQL expression ast over row, NULL as nil.
row is looked up as UPDATE's SET evaluation does (stmt/eval-update-
expr): storage attributes of table ns, or bare keys. A column is
typed as the attribute ns/column declares, unless column-types
({column-name attr-or-type-name}) says otherwise -- a domain's VALUE
takes the domain's base type. Parameters already in the expression
($1 in an ON CONFLICT ... WHERE) keep their numbers and the bound
values of params/*bound-params*; column parameters follow them.
Value of the SQL expression `ast` over `row`, NULL as nil.
`row` is looked up as UPDATE's SET evaluation does (stmt/eval-update-
expr): storage attributes of table `ns`, or bare keys. A column is
typed as the attribute `ns`/column declares, unless `column-types`
({column-name attr-or-type-name}) says otherwise -- a domain's VALUE
takes the domain's base type. Parameters already in the expression
(`$1` in an ON CONFLICT ... WHERE) keep their numbers and the bound
values of `params/*bound-params*`; column parameters follow them.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |