我正在使用用户定义的类型在 PlPython 中编写一个存储过程。我知道 Plpython 不支持用户定义的类型,所以,我为用户定义的类型创建了一个 CAST。当我调用 plpy.prepare 时,我仍然不断收到错误消息。我不确定我是否错误地使用了 CAST - 示例代码如下:
#User Defined Type - person
CREATE TYPE person As( name character varying(50), state character(2));
#Table definition using 'person'
CREATE TABLE manager As(id integer, mgr person)
#CAST for person
CREATE OR REPLACE FUNCTION person_to_text(person) RETURNS text AS 'SELECT ROW($1.*)::text' LANGUAGE SQL;
CREATE CAST (cv_person as text) WITH FUNCTION person_to_text(person)
#PlPython procedure
CREATE OR REPLACE FUNCTION load_portfolio_assoc (name text, state text) RETURNS integer AS $$
mgr_str ="('"+name+"','"+state+"')"
insert_qry = 'Insert into manager (mgr) values($1)'
value_type = ['text']
qry = plpy.prepare(insert_qry,value_type)
rv = plpy.execute(qry, [mgr_str])
return 1
$$ LANGUAGE plpython3u;