我为PostgreSQL类型gp
创建了类型别名money
,但是我无法从文档中弄清楚应该如何使用它。
我已经建立了一个测试表(和数据库):
CREATE TYPE gp AS (amt money);
CREATE TABLE test (val gp PRIMARY KEY);
但是无论我如何尝试插入行,都会失败
INSERT INTO test VALUES (1); -- column "val" is of type gp but expression is of type integer
INSERT INTO test VALUES ((1)); -- column "val" is of type gp but expression is of type integer
INSERT INTO test VALUES (CAST (1 AS gp)); -- cannot cast type integer to gp
INSERT INTO test VALUES (CAST (CAST (1 AS money) AS gp)); -- cannot cast type money to gp
INSERT INTO test VALUES ((amt=1)); -- column "amt" does not exist
INSERT INTO test VALUES ((amt=1)::gp); -- column "amt" does not exist
据我了解,gp
类型应该是别名:gp::money::numeric
,那么为什么不能将其从money
转换为money
的别名? / p>