我目前在我的 postgresql 查詢中遇到了一個在文本列中插入字串的奇怪問題,我將解釋:
我有一個具有以下架構的表:
CREATE TABLE IF NOT EXISTS template_formula
(
ID SERIAL PRIMARY KEY ,
formula VARCHAR(500) DEFAULT NULL,
display VARCHAR(500) DEFAULT NULL
);
該表將包含一個公式名稱和一個包含降價的顯示字串。
我的插入查詢如下:
DO $$
BEGIN
BEGIN
--- Insert Template Formula
INSERT INTO template_formula(id,formula,display) VALUES
(7,'1000*(sin(deg2rad($A)))-(init($A)','$\textrm{Calcul IPI décrit comme :}$ $$R = 1000 \cdot (sin(degr2rad(A_i)))-A_0 $$ $\textrm{où :}$ $$ \textrm{$A_i$} = \textrm{Valeur courante de lecture} $$ $$ \textrm{$A_0$} = \textrm{Valeur initiale} $$')
END;
COMMIT;
END;
$$
當我嘗試在 DBeaver 上執行此查詢時,出現以下錯誤:
SQL Error [42601]: Unterminated dollar quote started at position 290 in SQL DO $$
此錯誤是由于插入到顯示列的字串中的“$$”:
$$R = 1000
您知道如何將這兩個字符轉義為字串嗎?謝謝提前。
uj5u.com熱心網友回復:
對 DO 塊使用其他分隔符:
DO $do$
BEGIN
BEGIN
--- Insert Template Formula
INSERT INTO template_formula(id,formula,display) VALUES
(7,'1000*(sin(deg2rad($A)))-(init($A)','$\textrm{Calcul IPI décrit comme :}$ $$R = 1000 \cdot (sin(degr2rad(A_i)))-A_0 $$ $\textrm{où :}$ $$ \textrm{$A_i$} = \textrm{Valeur courante de lecture} $$ $$ \textrm{$A_0$} = \textrm{Valeur initiale} $$');
END;
COMMIT;
END;
$do$;
或者完全擺脫無用的 DO 塊:
BEGIN TRANSACTION;
INSERT INTO template_formula(id,formula,display) VALUES
(7,'1000*(sin(deg2rad($A)))-(init($A)','$\textrm{Calcul IPI décrit comme :}$ $$R = 1000 \cdot (sin(degr2rad(A_i)))-A_0 $$ $\textrm{où :}$ $$ \textrm{$A_i$} = \textrm{Valeur courante de lecture} $$ $$ \textrm{$A_0$} = \textrm{Valeur initiale} $$');
COMMIT;
(你也忘了;結束INSERT陳述句)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/446052.html
標籤:PostgreSQL 插入
上一篇:依賴于其他表的每個值的sql查詢
下一篇:在SQL中切換列舉值
