小编Nil*_*ils的帖子

插入Postgres中的自定义类型数组

我已经创建了一个自定义Postgres类型:

CREATE TYPE new_type AS (new_date timestamp, some_int bigint);
Run Code Online (Sandbox Code Playgroud)

我有一个表来存储new_type数组,例如:

CREATE TABLE new_table (
    table_id uuid primary key,
    new_type_list new_type[] not null
)
Run Code Online (Sandbox Code Playgroud)

我将数据插入此表中,如下所示:

INSERT INTO new_table VALUES (
    '*inApplicationGeneratedRandomUUID*',
    ARRAY[[NOW()::timestamp, '146252'::bigint],
          [NOW()::timestamp, '526685'::bigint]]::new_type[]
)
Run Code Online (Sandbox Code Playgroud)

我得到这个错误

ERROR: cannot cast type timestamp without time zone to new_type
Run Code Online (Sandbox Code Playgroud)

我想念什么?我也尝试过使用{}的数组语法,但没有更好的方法。

sql postgresql

5
推荐指数
1
解决办法
2520
查看次数

标签 统计

postgresql ×1

sql ×1