If-then子句postgresql
我定义了此函数:If-then子句postgresql,sql,database,postgresql,if-statement,plpgsql,Sql,Database,Postgresql,If Statement,Plpgsql,我定义了此函数: 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
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 ...
有什么问题吗?尝试使用
执行
并将ENDIF
更改为ENDIF
...
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;
...