Skip to content

标量与表达式 ​

标量表 ​

类型源码表示关键规则
int42signed i64,checked 算术
float3.5仅有限 f64,拒绝 NaN/Infinity
booltrue可由比较和 helper 产生
text"hello"UTF-8
uuidtyped string可作主键与索引
bytestyped hex string小写、偶数长度
date@2026-09-08无隐式本地时区或 calendar 算术
timestamp带 Z 或 offset精确时间点
duration30seconds整数精确单位
decimal P Sdecimal "19.90"precision 1..38,不隐式舍入

算术 ​

int、float、duration 和同类型 decimal 支持 checked 运算;溢出、除零或非有限 float 返回 E_ARITH。

同一个 decimal P S 类型之间可直接使用 +、-、一元负号和 sum。可能改变 scale 的运算必须写出结果类型和舍入模式,普通 *、/ 不会推断 decimal 结果:

text
derive {
  fee = decimal_mul amount (decimal "0.015") 12 2 "half_even"
  share = decimal_div amount (decimal "3") 12 2 "toward_zero"
  rounded = decimal_round amount 12 0 "half_up"
}

aggregate {avg_amount = decimal_avg amount 12 2 "half_even"} 用同样规则求平均。舍入模式为 exact、toward_zero、away_from_zero、floor、ceil、half_up 或 half_even;exact 在需要舍入时返回错误。旧 text 数据用 decimal_parse,精确改变 scale 用 decimal_rescale。

text
derive total = price + tax
filter retry_after <= 30seconds
derive expires_at = created_at + ttl

timestamp - timestamp 得到 duration。date 不读取当前时间、不隐式使用系统时区,也不执行月份/闰年式 calendar 运算。

Bool 与集合 helper ​

text
filter {
  priority >= 5
  && contains tags "release"
  && is_some assignee
}

可用比较、!、&&、||、contains、length、Option helper,以及有预算的 any/all。复杂表达式可用 {} 跨行;需要改变 precedence 时使用 ()。集合 predicate 使用 value -> expression,不用竖线闭包。

索引大小边界 ​

被主键、普通或 unique index 覆盖的 bytes leaf 最大 8192 octets,完整持久索引 key 最大 64 KiB;普通 value 上限为 16 MiB。超限写入、migration 或 restore 返回明确错误并原子回滚。

Last updated:

Released under the MIT License.