小编Abo*_*azi的帖子

在 postgresql 中将数据插入到表的用户定义类型元素中

我定义了 3 种类型如下:

CREATE TYPE EventDescriptionType AS ENUM (
 'felt report',
 'Flinn-Engdahl region',
 'local time',
 'tectonic summary',
 'nearest cities',
 'earthquake name',
 'region name'
);

CREATE TYPE ResourceReference AS (
  "resourceID" varchar(255)  
);

CREATE TYPE EventDescription AS (
 "text" text,
 "type" EventDescriptionType
);
Run Code Online (Sandbox Code Playgroud)

我还创建了一个包含上述类型元素的表格:

CREATE TABLE Event (
 "Event_id"                   serial PRIMARY KEY,
 "description"                EventDescription ARRAY
);
Run Code Online (Sandbox Code Playgroud)

然后,通过此命令将一些数据插入此表后:

insert into Event values (1,'{'L','felt report'}');
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

错误:“L”处或附近的语法错误第
1 行:插入事件值 (1,'{'L','felt report'}');

对于事件表中的元素“dexcription”,我分别将“1”作为 event_id 和“L”和“felt report”传递到数组中,分别用于 EventDescription 类型的“文本”和“类型”。

有人可以让我知道正确的方法吗?任何帮助,将不胜感激。

arrays postgresql sql-types insert create-table

3
推荐指数
1
解决办法
1547
查看次数

标签 统计

arrays ×1

create-table ×1

insert ×1

postgresql ×1

sql-types ×1