使用 python psycopg 将字符串参数传递给 sql-过程 (postgreSQL) 时发生错误

An error occurred when passing a string argument to a sql-procedure (postgreSQL) using python psycopg

我正在尝试使用 SQL 创建一个 SQL-procedure spAppeUpdateTimes(),它接受输入中 UPC 项目的字符串参数。但它不能正常工作。在输出中,该过程的输入不是一个固定的字符串,而是几个参数。这是因为项目的 UPC 值被拆分(划分)为单个字符。我应该怎么做才能避免这个错误?

CREATE OR REPLACE FUNCTION external.spAppeUpdatetTimes(
upc character varying)

  RETURNS void
  LANGUAGE 'sql'

  COST 100
  VOLATILE 
AS $BODY$

    update external."tbProducts" as pu
            set "eBayDiscontinued"= current_timestamp
    from external."tbProducts" as ps 
    where pu."eBayUPC"=upc;
    end;

  $BODY$;

  ALTER FUNCTION external.spappeupdatettimes(character varying)
       OWNER TO postgreadmin;

调用Python中的过程:

 cursor.callproc('external."spAppeUpdatetTimes"', (record[2]))

包含数据的table:

CREATE TABLE external."tbProducts"
("UPC" character varying(255) COLLATE pg_catalog."default",
    CONSTRAINT "tbProducts_pkey" PRIMARY KEY ("CWRPartNumber"))

但是,当我尝试使用该函数时,出现以下错误:

ProgrammingError('function external.spAppeUpdatetTimes(unknown, 
unknown, unknown, unknown, unknown, unknown) does not exist\nLINE 1: 
SELECT * FROM external."spAppeUpdatetTimes" 
 (\'1\',\'9\',\'3\',\'0\',...\n                      ^\nHINT:  No 
  function matches the given name and argument types. You might need 
  to add explicit type casts.

尝试明确加入数据。

类似

cursor.callproc('external."spAppeUpdatetTimes"', ''.join((record[2])))

问题已解决。在 python 代码中执行过程调用时,参数 'callproc' 必须是元组或列表。 mysqltutorial.org/calling-mysql-stored-procedures-python.

cursor.callproc('external."spAppeUpdatetTimes"', (record[2], ))