postgresql:“On Conflict”中的列引用不明确

问题描述 投票:0回答:0

我在 PGadmin 中创建了下表:

CREATE TABLE IF NOT EXISTS public.publications
(
    publication_id bigint NOT NULL DEFAULT nextval('eap_publications_publication_id_seq'::regclass),
    title character varying(1000) COLLATE pg_catalog."default" NOT NULL,
    author character varying(1000) COLLATE pg_catalog."default" NOT NULL,
    type integer[] NOT NULL,
    sys_publication_timestamp timestamp without time zone NOT NULL,
    tags integer[] NOT NULL,
    languages eap_control_vocabulary[],
    isbn character varying(255) COLLATE pg_catalog."default",
    url character varying(255) COLLATE pg_catalog."default",
    thumbnail_url character varying(255) COLLATE pg_catalog."default",
    target_audience integer[] NOT NULL,
    topic integer[] NOT NULL,
    related_projects integer[] NOT NULL,
    featured boolean,
    publication_status status,
    sys_creat_ip_address inet,
    sys_creat_timestamp timestamp without time zone NOT NULL,
    sys_modif_ip_address inet,
    sys_modif_timestamp timestamp without time zone,
    
    CONSTRAINT publications_pkey PRIMARY KEY (publication_id),
    
)

我做了以下功能来做插入/更新:

CREATE OR REPLACE FUNCTION public.upsert_publication(
    titlepub character varying(1000),
    authorpub character varying(1000),
    typepub integer[],  
    tagspub integer[],
    languagespub text,
    isbnpub character varying(255),
    urlpub character varying(255),
    thumbnail_urlpub character varying(255),
    target_audiencepub integer[],
    topicpub integer[],
    related_projectspub integer[],
    featuredpub boolean,
    publication_statuspub status,
    sys_creat_ip_addresspub inet,
    sys_modif_ip_addresspub inet)
    
    RETURNS jsonb
    LANGUAGE 'plpgsql'
    
    AS $BODY$

    declare
        pub_timestamp timestamp without time zone;
        pub_creat_timestamp timestamp without time zone;
        pub_modif_timestamp timestamp without time zone;
    
    BEGIN
    
        pub_timestamp :=current_timestamp;
        pub_creat_timestamp :=current_timestamp;
        pub_modif_timestamp :=current_timestamp;

        INSERT INTO public.publications 
        VALUES (DEFAULT,titlepub, authorpub, typepub, pub_timestamp, tagspub, languagespub,isbnpub,urlpub,thumbnail_urlpub, 
        target_audiencepub, topicpub, related_projectspub, featuredpub, publication_statuspub, sys_creat_ip_addresspub, pub_creat_timestamp, sys_modif_ip_addresspub,pub_modif_timestamp )
        ON CONFLICT (title, author) 
        DO 
           UPDATE SET title=EXCLUDED.title, author=EXCLUDED.author, type=EXCLUDED.type, sys_publication_timestamp=current_timestamp, 
           tags=EXCLUDED.tags, languages=EXCLUDED.languages,isbn=EXCLUDED.isbn,url=EXCLUDED.url,thumbnail_url=EXCLUDED.thumbnail_url, 
           target_audience=EXCLUDED.target_audience, topic=EXCLUDED.topic, related_projects=EXCLUDED.related_projects, featured=EXCLUDED.featured,
           publication_status=EXCLUDED.publication_status, sys_creat_ip_address=EXCLUDED.sys_creat_ip_address, sys_creat_timestamp=current_timestamp, 
           sys_modif_ip_address=EXCLUDED.sys_modif_ip_address, sys_modif_timestamp=current_timestamp;

    end;

    $BODY$;

但是每次我尝试使用它时,都会出现以下错误:

“错误:列引用“标题”不明确 第 4 行:关于冲突(标题、作者) ^ 详细信息:它可以引用 PL/pgSQL 变量或表列。”

我怎样才能使这个引用不那么模糊?我尝试在 ON CONFLICT 中的“标题”前面添加表的名称,但它只是产生了语法错误。

编辑:抱歉,我对这些功能进行了多次尝试并发布了错误的功能。 这是赖特的,我按照建议更改了输入参数的名称。

这解决了我的问题 再次感谢和抱歉

sql postgresql insert-update
© www.soinside.com 2019 - 2024. All rights reserved.