我在 PostgreSQL 9.5 中编写了一个 PL/pgSQL 函数。它编译得很好,但是当我从 pgAdmin3 调用它时,它给了我一个错误。似乎用函数中传递的参数替换列的动态查询不起作用。
下面是我的功能:
CREATE OR REPLACE FUNCTION insertRecordsForNotification(username text, state text, district text, organizationId text, bloodGroup text, status text, approveRejectStatus text, emailSubject text, emailBody text, notificationStatus text) RETURNS boolean AS $$
DECLARE
id int;
r moyadev.user%rowtype;
_where text :=
concat_ws(' AND '
, CASE WHEN state IS NOT NULL THEN 'state = $2' END
, CASE WHEN district IS NOT NULL THEN 'district = $3' END
, CASE WHEN bloodGroup IS NOT NULL THEN …Run Code Online (Sandbox Code Playgroud)