如何修复出现错误的函数:“格式错误的数组常量”“详细信息:输入的意外结尾”?

时间:2019-06-07 10:27:47

标签: sql postgresql plpgsql

我正在为我的postgresql数据库创建一个函数,并且需要将6位字符串编码为ascii字符。虽然我得到错误:格式不正确的数组文字。我该如何解决?

为解决这个问题,我已经研究过使用右括号和单引号。但是我还没有成功。

`CREATE OR REPLACE FUNCTION example(payload bit varying) 
RETURNS text AS $str$ 
DECLARE 
    str text := ''; 
    len int; 
    i int; 
    tbl text[] := '{@,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,[,\\,],^,_," ",!,"\"",#,$,%,&,‘,(,),*,+,",-,.,/,0,1,2,3,4,5,6,7,8,9,:,;,<,=,>,?}'::text[];
BEGIN
        .....
END; 
$str$ LANGUAGE plpgsql 
IMMUTABLE 
;`

Below the error message:
ERROR:  malformed array literal: `"@,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,[,\\,],^,_," ",!,"\"",#,$,%,&,‘,(,),*,+,",-,.,/,0,1,2,3,4,5,6,7,8,9,:,;,<,=,>,?}"

LINE 1: SELECT '{@,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y...
               ^
DETAIL:  Unexpected end of input.
QUERY:  SELECT '{@,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,[,\\,],^,_," ",!,"\"",#,$,%,&,‘,(,),*,+,",-,.,/,0,1,2,3,4,5,6,7,8,9,:,;,<,=,>,?}'::text[]

CONTEXT:  PL/pgSQL function example(bit varying) line 7 during statement block local variable initialization
SQL state: 22P02

0 个答案:

没有答案