html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,issue,performed_via_github_app
https://github.com/simonw/sqlite-utils/issues/358#issuecomment-1257136801,https://api.github.com/repos/simonw/sqlite-utils/issues/358,1257136801,IC_kwDOCGYnMM5K7mKh,11597658,2022-09-25T07:15:07Z,2022-09-25T07:15:59Z,NONE,"HI Simon,
looks good, I noticed you wanted to use a regex to detect it, you might be interested in [github.com/iafisher/sqliteparser](https://github.com/iafisher/sqliteparser) which creates an ast of the create table statement, not every option supported yet but i forked it and am adding all the possible options in a create table (and create index) statement. ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",1082651698,
https://github.com/simonw/sqlite-utils/issues/358#issuecomment-1255341690,https://api.github.com/repos/simonw/sqlite-utils/issues/358,1255341690,IC_kwDOCGYnMM5K0v56,9599,2022-09-22T17:35:23Z,2022-09-22T17:35:23Z,OWNER,Make me think also that `sqlite-utils create-table` should have an option to dump out the SQL without actually creating the table.,"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",1082651698,
https://github.com/simonw/sqlite-utils/issues/358#issuecomment-1255340974,https://api.github.com/repos/simonw/sqlite-utils/issues/358,1255340974,IC_kwDOCGYnMM5K0vuu,9599,2022-09-22T17:34:45Z,2022-09-22T17:34:45Z,OWNER,"A few other recipes off the top of my head:
- `title:maxlength:20` - set a max length, `length(title) <= 20`
- `created:date` - check for `yyyy-mm-dd` date, `select :date == date(:date) is not null` ([demo](https://latest.datasette.io/_memory?sql=select+%3Adate+%3D%3D+date%28%3Adate%29+is+not+null&date=2022-01-01))
- `age:positiveint` - check `age` is a positive integer, `printf('%', age) = age and age > 0` (untested)","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",1082651698,
https://github.com/simonw/sqlite-utils/issues/358#issuecomment-1255333969,https://api.github.com/repos/simonw/sqlite-utils/issues/358,1255333969,IC_kwDOCGYnMM5K0uBR,9599,2022-09-22T17:29:09Z,2022-09-22T17:29:09Z,OWNER,"Quick demo of a check constraint for JSON validation:
```
sqlite> create table test (id integer primary key, tags text, check (json(tags) is not null));
sqlite> sqlite> insert into test (tags ('[""one"", ""two""]');
sqlite> insert into test (tags) values ('[""one"", ""two""');
Error: stepping, malformed JSON (1)
```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",1082651698,
https://github.com/simonw/sqlite-utils/issues/358#issuecomment-1255332217,https://api.github.com/repos/simonw/sqlite-utils/issues/358,1255332217,IC_kwDOCGYnMM5K0tl5,9599,2022-09-22T17:27:34Z,2022-09-22T17:27:34Z,OWNER,"I've been thinking about this more recently.
I think the first place to explore these will be in the `create-table` command (and underlying APIs).
Relevant docs: https://www.sqlite.org/lang_createtable.html#check_constraints
> A CHECK constraint may be attached to a column definition or specified as a table constraint. In practice it makes no difference. Each time a new row is inserted into the table or an existing row is updated, the expression associated with each CHECK constraint is evaluated and cast to a NUMERIC value in the same way as a [CAST expression](https://www.sqlite.org/lang_expr.html#castexpr). If the result is zero (integer value 0 or real value 0.0), then a constraint violation has occurred. If the CHECK expression evaluates to NULL, or any other non-zero value, it is not a constraint violation. The expression of a CHECK constraint may not contain a subquery.
Something like this:
sqlite-utils create-table data.db entries id integer title text tags text --pk id --check tags:json
Where `--check tags:json` uses a pre-baked recipe for using the SQLite JSON function to check that the content is valid JSON and reject it otherwise.
Then can bundle a bunch of other pre-baked recipes, but also support the following:
--check 'x > 3' --check 'length(phone) >= 10'
The besign reason for the `column:recipe` format here is to reuse `--check` for both pre-defined recipes that affect a single column AND for freeform expressions that get added to the end of the table.
Detecting `column name:recipe` with a regex feels safe to me.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",1082651698,
https://github.com/simonw/sqlite-utils/issues/358#issuecomment-996482595,https://api.github.com/repos/simonw/sqlite-utils/issues/358,996482595,IC_kwDOCGYnMM47ZR4j,11597658,2021-12-17T06:57:51Z,2021-12-17T23:24:16Z,NONE,"> This goes beyond the `transform()` method - the curious methods that create new SQL tables could benefit from the ability to add `CHECK` constraints too.
>
> I haven't used these myself, do you have any `CREATE TABLE` examples that use them that you can share?
I'm using them myself for the first time as well, this is a tutorial of how to use (and change) them in sqlite: https://www.sqlitetutorial.net/sqlite-check-constraint/","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",1082651698,
https://github.com/simonw/sqlite-utils/issues/358#issuecomment-996232461,https://api.github.com/repos/simonw/sqlite-utils/issues/358,996232461,IC_kwDOCGYnMM47YU0N,9599,2021-12-16T22:10:39Z,2021-12-16T22:10:39Z,OWNER,"This goes beyond the `transform()` method - the curious methods that create new SQL tables could benefit from the ability to add `CHECK` constraints too.
I haven't used these myself, do you have any `CREATE TABLE` examples that use them that you can share?","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",1082651698,