我有一个返回多个表的函数,该函数用于在flutter中查询。当我想显示基于id的用户活动时,我使用此功能。但是当我尝试在postgres中执行时,它返回null。但是,当我将var_id更改为ID(例如ID号1)或其他名称时,数据就会出现。这是我的功能
DECLARE
headers JSONB;
body JSONB;
result JSONB;
var_id BIGINT;
BEGIN
headers = request->'headers';
body = request->'body';
var_id = body->>'id';
SELECT json_agg(row_to_json(X))Into result
FROM(SELECT
logs.user_activities.activity,
logs.user_activities.created_at,
sso.users.id,
logs.user_activities.id_user
FROM
logs.user_activities
INNER JOIN sso.users ON (logs.user_activities.id_user = sso.users.id)
WHERE
sso.users.id = var_id
ORDER BY
logs.user_activities.created_at DESC)X;
IF result IS NULL THEN
result = '[]';
END IF;
RETURN result;
END;
当我选择要显示活动的用户时,我使用此功能。