pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PegoraroF10 <marcos@f10.com.br>
To: pgsql-general@postgresql.org
Subject: Transition Tables doesn´t have OID
Date: Sat, 1 Dec 2018 05:22:18 -0700 (MST)
Message-ID: <1543666938082-0.post@n3.nabble.com> (raw)

I´m trying to use transition tables for auditing purposes.

create trigger MyTableAudit_UPD after update on MyTable referencing old
table as Transition_old new table as Transition_new for each statement
execute procedure AuditTable();

create or replace function AuditTable() returns trigger language plpgsql as
$$
if (TG_OP = 'UPDATE') then
  insert into audittable(table_name, oid, audit_action, user_id,
table_schema, values_old, values_new)
  select TG_TABLE_NAME, Transition_new.oid, TG_OP, CURRENT_USER,
TG_TABLE_SCHEMA,  row_to_json(Transition_old.*)::jsonb,
row_to_json(Transition_new.*)::jsonb from Transition_new inner join
Transition_old on Transition_new.OID = Transition_old.OID;
elsif (TG_OP = 'DELETE') then
  insert into audittable(table_name, oid, audit_action, user_id,
table_schema, values_old)
  select TG_TABLE_NAME, Transition_old.oid, TG_OP, CURRENT_USER,
TG_TABLE_SCHEMA, row_to_json(Transition_old.*)::jsonb from Transition_old;
end if;

[42703] ERROR: column transition_new.oid does not exist Where: função
PL/pgSQL audittable() linha 14 em comando SQL

I would like to user OID value because we change our primary keys,
sometimes, OID doesn´t.

So, there is a way to get OID on transition tables ?



--
Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html




view thread (9+ messages)  latest in thread

Message-ID: <1543666938082-0.post@n3.nabble.com>
Permalink:  ../1543666938082-0.post@n3.nabble.com/
Also on:    postgresql.org/message-id/1543666938082-0.post@n3.nabble.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: marcos@f10.com.br
  Subject: Re: Transition Tables doesn´t have OID
  In-Reply-To: <1543666938082-0.post@n3.nabble.com>
  References: <1543666938082-0.post@n3.nabble.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox