【发布时间】:2019-08-06 14:10:00
【问题描述】:
问题是标题。我们有一个 postgreSQL 数据库,我们想在其中保存一些路径,并且数据库从路径中删除反斜杠(\)。
功能:
CREATE OR REPLACE FUNCTION public.add_filenotification_array(IN fninput public.filenotification_input [])
RETURNS Table(TYPE public."filenotification") AS
$$
DECLARE
fn public.filenotification_input;
filenotification public.filenotification;
filenotificationlist public.filenotification [];
BEGIN
FOREACH fn IN ARRAY fninput LOOP
INSERT INTO public."FileNotification"("FileLocation", "FileTargetLocation", "DocumentLanguage", "LastUpdate", "idStatus", "FileSize")
VALUES (fn.filelocation, fn.filetargetlocation, fn.documentlanguage, CURRENT_TIMESTAMP, 0, 0)
RETURNING "id", "FileLocation", "FileTargetLocation", "DocumentLanguage", "LastUpdate", "idStatus"
INTO filenotification.id, filenotification.filelocation, filenotification.filetargetlocation, filenotification.documentlanguage, filenotification.lastupdate, filenotification.idstatus;
filenotificationlist := array_append(filenotificationlist, filenotification);
END LOOP;
RETURN QUERY
SELECT * FROM unnest(filenotificationlist::public.filenotification []);
END;
$$
LANGUAGE plpgsql;
文件类型:
TYPE filenotification AS (
"id" integer,
"filelocation" character varying,
"filetargetlocation" character varying,
"documentlanguage" character varying,
"lastupdate" timestamp,
"idstatus" integer
);
TYPE filenotification_input AS (
"filelocation" character varying,
"filetargetlocation" character varying,
"documentlanguage" character varying
);
从应用程序中,我们发送filenotification 的java.sql.Array,在filelocation 和filetargetlocation 参数处具有正确的路径,结果完全没有反冲。我们的问题是:发生了什么事?为什么要删除反斜杠?
编辑:如果我们在函数参数中加入 4 个反斜杠,那么它会输出 1 个反斜杠。如果我们在函数参数中加入 8 个反斜杠,那么它会输出 2 个反斜杠
【问题讨论】:
-
几乎可以肯定不是。你有任何证据支持你的主张吗? java 和 PostgreSQL 端的值的示例?来自 psql 输出的样本?
-
我不明白你的问题。我们将“C:\\Users\\kh\\Desktop\\workstuff\\samples\\test_in\\someBook.tif”放入数据库,得到“C:UserkhDesktopworkstuffsamplestest_insomeBook.tif”
标签: java spring postgresql plpgsql pgadmin-4