如果您能给我提建议,我将不胜感激. 我在node.js下使用Postgres 16和PostgreSQL客户端 存在一个具有用户定义类型的表:
CREATE TYPE my_type AS ENUM ('value1', 'value2');
CREATE TABLE table2
(
id bigint PRIMARY KEY,
t1_id ...,
field1 my_type default 'value1'
field2 integer
);
我想在联接中使用它:
SELECT
table1.field1 as t1f1, ...
array_agg(table2.field1) as t2f1,
array_agg(table2.field2) as t2f2,
array_agg(table3.field1) as t3f1,
...
FROM table1
LEFT JOIN table2 ON table2.t1_id = table1.id
LEFT JOIN table 3 ON table3.t1_id=table1.id
...
GROUP BY table1.id
但出于某种原因,我得到了这一列(在本例中为t2f1)的结果,它是一个带有原始postgres数组的字符串,而不是像其他列那样的常规数组:
[
{
t1f1: "blah-blah",
t2f1: "{NULL, NULL, NULL, NULL}",
t2f2: [NULL, NULL, NULL, NULL],
t3f1: [NULL, NULL, NULL, NULL],
}
]
因此,问题是如何强制postgres客户端正确处理枚举.