我有一张桌子叫书
CREATE TABLE book
(
id smallint NOT NULL DEFAULT 0,
bname text,
btype text,
bprices numeric(11,2)[],
CONSTRAINT key PRIMARY KEY (id )
)
和一个功能save_book
CREATE OR REPLACE FUNCTION save_book(thebook book)
RETURNS text AS
$BODY$
DECLARE
myoutput text :='Nothing has occured';
BEGIN
update book set
bname=thebook.bname,
btype=thebook.btype,bprices=thebook.bprices WHERE id=thebook.id;
IF FOUND THEN
myoutput:= 'Record with PK[' || thebook.id || '] successfully updated';
RETURN myoutput;
END IF;
BEGIN
INSERT INTO book values(thebook.id,thebook.bname,thebook.btype,
thebook.bprices);
myoutput:= 'Record successfully added';
END;
RETURN myoutput;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
现在当我调用函数
SELECT save_book('(179,the art of war,fiction,{190,220})'::book);
我得到了错误
ERROR: malformed array literal: "{190"
SQL state: 22P02
Character: 18
我不明白,因为我没有看到阵列格式的任何错误,没有任何帮助吗?
ERROR: syntax error at or near "art"
ave_book((179, 'the art of war', 'fiction', '{190,220}')::book
答案是,就像安德里(Andriy)所说的那样。
ave_book((179,the art of war,fiction,'{190,220}')::book
。构造的行不需要引号。