错误:运算符不存在:数字 ~* 未知

J.O*_*sen 2 sql postgresql

我需要domain在 PostgreSQL 中创建一个价格。价格必须是NUMERIC(9,2)9 为精度,2 为小数位数。尝试创建域时获取:

ERROR: operator does not exist: numeric ~* unknown Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.

询问:

CREATE DOMAIN d_price AS NUMERIC(9, 2) NOT NULL 
CONSTRAINT Product_price_can_contain_only_double_precision_value
CHECK(VALUE ~*'^(([[:digit:]])+\.([[:digit:]]){2})$');
Run Code Online (Sandbox Code Playgroud)

sma*_*thy 5

在使用字符串运算符之前,您需要将数值作为字符串,将其更改VALUE为:CAST(VALUE AS TEXT)