我打算通过临时表中的策略更改来记录用户 ID。以下应返回记录的 id,但它确实返回空行。不知何故,ID丢失了:S行数还可以,ID在表中,我不知道我做错了什么......
BEGIN;
SELECT * FROM policy_change_update(ARRAY[1,2,3]);
SELECT * FROM user_read_all_by_policy_change();
COMMIT;
功能:
policy_change_provide_store:
CREATE FUNCTION policy_change_provide_store ()
RETURNS VOID
AS
$BODY$
BEGIN
CREATE TEMPORARY TABLE policy_change (
user_id INT4
);
EXCEPTION WHEN duplicate_table THEN
RETURN;
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
policy_change_update
CREATE FUNCTION policy_change_update (
IN user_ids INT4 []
)
RETURNS VOID
AS
$BODY$
BEGIN
PERFORM policy_change_provide_store();
INSERT INTO policy_change
SELECT inserted_user_id FROM unnest(user_ids) AS inserted_user_id
WHERE NOT EXISTS(SELECT 1 FROM policy_change WHERE user_id = inserted_user_id);
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
user_read_all_by_policy_change
CREATE FUNCTION user_read_all_by_policy_change ()
RETURNS TABLE (
user_id INT4
)
AS
$BODY$
BEGIN
PERFORM policy_change_provide_store();
RETURN QUERY
SELECT user_id FROM policy_change ORDER BY user_id DESC;
IF NOT FOUND THEN
RAISE SQLSTATE 'UE404' USING MESSAGE = 'not found';
END IF;
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
任何想法?