正確には「制約」ではない。データの値を制限しないから。
成果物
情報源
これを参考に、ほぼ全パターン網羅してみる。
リテラル値
create table A(A int default 0); create table B(A int default -1); create table C(A real default -0.1); create table D(A text default 'A'); create table E(A blob default x'0'); create table F(A text default NULL); create table G(A text default CURRENT_TIME); create table H(A text default CURRENT_DATE); create table I(A text default CURRENT_TIMESTAMP);
ちなみに時刻関係はUTC時刻で、以下の書式だった。
時刻 | 書式 |
---|---|
CURRENT_TIME |
22:33:58 |
CURRENT_DATE |
2019-08-29 |
CURRENT_TIMESTAMP |
2019-08-29 22:33:58 |
式
create table A(A text default (1+1)); create table B(A text default (random())); create table C(A text default (cast(random() as text))); create table D(A text default (1 collate binary)); create table E(A text default (1 not like 2)); create table F(A text default (1 not glob 2)); create table G(A text default (1 not regexp 2)); create table H(A text default (1 not match 2)); create table I(A text default (1 isnull)); create table J(A text default (1 notnull)); create table K(A text default (1 not null)); create table L(A text default (1 is null)); create table M(A text default (1 is not null)); create table N(A text default (4 not between 0 and 3)); create table O(A text default (4 not in (1,2,3))); create table P(A text default (4 not in (select 1,2,3))); create table Q(A text default (not exists (select 1,2,3))); create table R(A text default ((select 1,2,3))); create table S(A text default (case 1 when 1 then 1 else 2 end));
match
はFTS5で出てきたな。regexp
って正規表現? 拡張なしで使えたの?
なんかエラー出た。よくわからん。
Error: near line 16: default value of column [A] is not constant Error: near line 17: default value of column [A] is not constant Error: near line 18: default value of column [A] is not constant
解決できなかった。
sqlite3 :memory: "create table P(A text default (4 not in (select 1,2,3)));"
Error: default value of column [A] is not constant
「エラー:列[A]のデフォルト値は定数ではありません」ということ。
sqlite3 :memory: "select 4 not in (select 1,2,3);"
Error: sub-select returns 3 columns - expected 1
列を1つにしてみる。
sqlite3 :memory: "select 4 not in (select 1);"
1
もう一度。
sqlite3 :memory: "create table P(A text default (4 not in (select 1)));"
Error: default value of column [A] is not constant
あれ? なぜだ。もしや型?
sqlite3 :memory: "create table P(A int default (4 not in (select 1)));"
Error: default value of column [A] is not constant
ダメ。何なの? 真偽値の0
か1
のうち0
が入ると期待しているのだが……。式だけど定数だと思うのだが。
ウインドウ関数も使えるらしいのだが、それ自体がなんか難しそうなので先送り。
対象環境
- Raspbierry pi 3 Model B+
- Raspbian stretch 9.0 2018-11-13
- bash 4.4.12(1)-release
- SQLite 3.29.0
- MeCab 0.996ユーザ辞書
$ uname -a Linux raspberrypi 4.19.42-v7+ #1218 SMP Tue May 14 00:48:17 BST 2019 armv7l GNU/Linux
前回まで
- SQLite3学習 俯瞰まとめ
- SQLite3学習 環境構築まとめ
- SQLite3学習 インタフェースまとめ(C言語、CLI、対話モード、Tcl...)
- SQLite3学習 ドットコマンドまとめ
- SQLite3学習 JSON拡張まとめ
- SQLite3学習 FTSまとめ(ICU, MeCab)
- SQLite3学習 再帰クエリ(WITH RECURSIVE)
- SQLite3学習 R-Treeモジュール
- SQLite3学習 Geopoly(2次元ベクタ画像の生成)
- SQLite3学習 拡張関数(generate_series)
- SQLite3学習 拡張ライブラリ数学関数(extension-functions.c)
- SQLite3学習 謎と名前
- SQL文の分類(DDL,DML,TCL,DCL)
- SQL構文 alter(rename)
- SQL構文 alter(add column)概要
- SQL構文 alter(add column)制約
- SQL構文 alter(add column)sqlite_master変更しても反映されない
- SQL構文 alter(add column)スキーマ再定義(テーブル再作成による定義変更)
- SQL構文 analyze
- SQL構文 attach/detach
- SQLite3構文 begin,end,commit,rollback,savepoint(deferred,immediate,exclusive)
- SQLite3構文 コメント
- SQLite3構文 create/drop
- SQLite3構文 index(create/drop)
- SQLite3構文 table(create/drop)