我在postgresql中返回值时遇到麻烦,我创建了这样的函数(EDITED):
CREATE OR REPLACE FUNCTION GetComissionamento(pv varchar(50))
RETURNS SETOF tb_comissionamentos AS
$$
BEGIN
SELECT com.* FROM tb_vendas as vendas
INNER JOIN tb_pagamentos as pg on vendas.id_venda = pg.id_venda
INNER JOIN tb_comissionamentos as com on vendas.id_venda = com.id_venda
AND com.id_pagamento = pg.id_pagamento
WHERE id_venda_imobiliaria = pv;
END
$$
LANGUAGE plpgsql;
我想在表格tb_comissionamento上返回数据,如查询所示。 我该怎么办?当我调用该函数时,我收到了错误消息:
ERROR: query has no destination for result data
HINT: If you want to discard the results of a SELECT, use PERFORM instead.
答案 0 :(得分:2)
这很糟糕。
VIEW
而不是功能像这样,
CREATE VIEW GetComissionamento AS
SELECT com.* FROM tb_vendas as vendas
INNER JOIN tb_pagamentos as pg on vendas.id_venda = pg.id_venda
INNER JOIN tb_comissionamentos as com on vendas.id_venda = com.id_venda
AND com.id_pagamento = pg.id_pagamento;
然后(其中$ pv是你的价值),
SELECT *
FROM GetComissionamento
WHERE id_venda_imobiliaria = $pv;
sql
而不是plpgsql
像这样,
CREATE FUNCTION GetComissionamento(varchar(50))
RETURNS tb_comissionamentos AS $$
SELECT com.* FROM tb_vendas as vendas
INNER JOIN tb_pagamentos as pg on vendas.id_venda = pg.id_venda
INNER JOIN tb_comissionamentos as com on vendas.id_venda = com.id_venda
AND com.id_pagamento = pg.id_pagamento
WHERE id_venda_imobiliaria = $1;
$$ LANGUAGE SQL;
RETURN QUERY
。像这样,
CREATE OR REPLACE FUNCTION GetComissionamento (pv varchar(50))
RETURNS tb_comissionamentos AS $$
BEGIN
RETURN QUERY
SELECT com.* FROM tb_vendas as vendas
INNER JOIN tb_pagamentos as pg on vendas.id_venda = pg.id_venda
INNER JOIN tb_comissionamentos as com on vendas.id_venda = com.id_venda
AND com.id_pagamento = pg.id_pagamento
WHERE id_venda_imobiliaria = pv;
-- error checking or whatever
RETURN;
END;
$$ LANGUAGE plpgsql;
答案 1 :(得分:0)
是的,得到了错误,忘了返回查询
class UserService { d: UserGroupDao =>
val dao = d
def read(userId: String): Future[Option[User]] = dao.readUser(userId)
}
class GroupService { svc: UserService =>
def createGroup(group: Group): Future[Either[String, String]] = {
svc.read(group.ownerId) map {
case Some(_) => svc.dao.createGroup(group)
case None => Left("Invalid User!")
}
}
}