【问题标题】:If then clause postgresqlif then 子句 postgresql
【发布时间】:2019-09-28 05:06:08
【问题描述】:

我已经定义了这个函数:

SELECT dblink_connect('conne1', 'dbname=bdp3e1');
SELECT dblink_connect('conne2', 'dbname=bdp3e2');

CREATE OR REPLACE FUNCTION insertEditorial(nombre VARCHAR(100), CIF INTEGER, ubicacion VARCHAR(50))
RETURNS void AS
$insertEditorial$
BEGIN
    IF ubicacion IS NULL THEN
        dblink_exec('conne2', 'INSERT INTO Editorial VALUES (nombre, CIF);');
    ELSE
        dblink_exec('conne1', 'INSERT INTO Editorial VALUES (nombre, CIF, ubicacion);');
    ENDIF;
END;
$insertEditorial$ LANGUAGE plpgsql;

但是在执行时,postgreSQL 会返回以下错误:

psql:PR3_Procedures.sql:14: ERROR:  syntax error at or near "dblink_exec"
LINE 6:         dblink_exec('conne2', 'INSERT INTO Editorial VALUES ...

这有什么问题?

【问题讨论】:

    标签: sql database postgresql if-statement plpgsql


    【解决方案1】:

    尝试使用PERFORM并将ENDIF更改为END IF

    ...
    IF ubicacion IS NULL THEN
        PERFORM dblink_exec('conne2', 'INSERT INTO Editorial VALUES (nombre, CIF);');
    ELSE
        PERFORM dblink_exec('conne1', 'INSERT INTO Editorial VALUES (nombre, CIF, ubicacion);');
    END IF;
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-03
      • 1970-01-01
      • 2021-12-09
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多