如何在 postgres 触发器中从 dual table 传递带有 userenv 的新旧标识符
how to pass the new old identifier with userenv from dual table in postgres trigger
我将 oracle 脚本转换为 PostgreSQL,这需要用户更新我使用的 Oracle 触发器中的最后登录信息:
if inserting then
:new.last_update := sysdate
select osuser into :new.updated_by from gv@session where audsid =
(select userenv('sessionid') from dual);
end if;
如何转换为 postgres?我在 select 之后卡住了......来自 dual 和 dual is not a table in postgres.
if TG_OP = 'INSERT' then
new.last_update :=current_timestamp;
SELECT usename INTO :new.update_by
FROM pg_user
WHERE usesysid = (SELECT ..(I got stuck here)
RETURN NEW;
END IF;
如何使触发功能与双table一起正常工作?
首先让我们解决 dual
问题。 Oracle 语法要求完成 FROM 子句。当没有实际的 table 而不是子 select 时,使用 dual 来完成所需的语法。 Postgres 不要求完成 FROM 子句。以下是相同的查询。
Oracle: Postgres:
Select 'abc' from dual; Select 'abc';
你的其他问题,看来你运气不好。在 Oracle 中,变量 OSUSER
是客户端上的用户(通过 Oracle 客户端 - OCI),即使这与用于登录数据库的用户 ID 不同。 但 Postgres 不提供此功能。
我将 oracle 脚本转换为 PostgreSQL,这需要用户更新我使用的 Oracle 触发器中的最后登录信息:
if inserting then
:new.last_update := sysdate
select osuser into :new.updated_by from gv@session where audsid =
(select userenv('sessionid') from dual);
end if;
如何转换为 postgres?我在 select 之后卡住了......来自 dual 和 dual is not a table in postgres.
if TG_OP = 'INSERT' then
new.last_update :=current_timestamp;
SELECT usename INTO :new.update_by
FROM pg_user
WHERE usesysid = (SELECT ..(I got stuck here)
RETURN NEW;
END IF;
如何使触发功能与双table一起正常工作?
首先让我们解决 dual
问题。 Oracle 语法要求完成 FROM 子句。当没有实际的 table 而不是子 select 时,使用 dual 来完成所需的语法。 Postgres 不要求完成 FROM 子句。以下是相同的查询。
Oracle: Postgres:
Select 'abc' from dual; Select 'abc';
你的其他问题,看来你运气不好。在 Oracle 中,变量 OSUSER
是客户端上的用户(通过 Oracle 客户端 - OCI),即使这与用于登录数据库的用户 ID 不同。 但 Postgres 不提供此功能。