SQLite User Forum

How to obtain check constraints?
Login

How to obtain check constraints?

(1) By anonymous on 2022-11-08 10:02:35 [link] [source]

How to obtain all check constraints of a table in sqlite.

(2) By ddevienne on 2022-11-08 10:27:51 in reply to 1 [link] [source]

Beside parsing the DDL SQL yourself, there's unfortunately no pragma for that :(

All you can do with CHECK constraints is disable/enable them: https://www.sqlite.org/pragma.html#pragma_ignore_check_constraints

(3) By anonymous on 2022-11-08 18:39:27 in reply to 1 [link] [source]

At present, the only way I know to get the CHECK constraints is via parsing the DDL. I would love to see a more complete table_info/xinfo() (or additional pragma, or an extension).

In lieu of some official solution, you can take a look at something like the following for the general idea:

https://github.com/lempiy/Sqlite3CreateTableParser

(4) By anonymous on 2022-11-08 19:06:00 in reply to 1 [source]

Another interesting sqlite parser which parses out CHECK is:

http://codeschool.github.io/sqlite-parser/demo/

Putting that kind of parser (or the sqlite DDL parsing mechanism?) in an extension (as an sql user function) whether as an AST or converted to text (perhaps a second function?) would make handling the sqlite DDL a bit easier. I would presume that the 'use-case' (note: I generally dislike use-case based justification) is in database handling tooling.