这是我的函数声明和正文的一部分:
CREATE OR REPLACE FUNCTION access_update() RETURNS void AS $$ DECLARE team_ids bigint[]; BEGIN SELECT INTO team_ids "team_id" FROM "tmp_team_list"; UPDATE "team_prsnl" SET "updt_dt_tm" = NOW(), "last_access_dt_tm" = NOW() WHERE "team_id" IN team_ids; END; $$ LANGUAGE plpgsql;
我想team_ids成为一个整数数组,然后可以在UPDATE语句中使用它。这个函数给我这样的错误:
team_ids
UPDATE
psql:functions.sql:62: ERROR: syntax error at or near "team_ids" LINE 13: AND "team_id" IN team_ids;
更快更简单的用FROM在您的条款UPDATE声明:
FROM
UPDATE team_prsnl p SET updt_dt_tm = now() ,last_access_dt_tm = now() FROM tmp_team_list t WHERE p.team_id = t.team_id;
除此之外,在使用数组进行操作时,该WHERE子句必须是
WHERE
WHERE team_id = ANY (team_ids)
该IN构造适用于集合,而不适用于数组。
IN