错误:列“ urls”的类型为url [],但表达式的类型为record []

时间:2019-12-17 06:23:55

标签: postgresql

ddl

CREATE TYPE url AS (
    url varchar,
    status int4);


CREATE TABLE public.tiantang_page (
    href varchar NOT NULL,
    status int4 NOT NULL,
    description varchar NOT NULL,
    urls url[] NULL,
    urltest url NULL
);

sql

INSERT INTO public.tiantang_page
(href, status, description, urls, urltest)
VALUES('', 0, '', array[row('test',0)], row('test',0));

错误

SQL Error [42804]: ERROR: column "urls" is of type url[] but expression is of type record[]
  Hint: You will need to rewrite or cast the expression.
  Position: 97

1 个答案:

答案 0 :(得分:2)

根据错误消息,您需要使用url投射回复合::类型

INSERT INTO public.tiantang_page
(href, status, description, urls, urltest)
VALUES('', 0, '', array[row('test',0)::url], row('test',0)::url);

SqlFiddle