Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gT4WF-0001Rr-Tn for pgsql-general@arkaria.postgresql.org; Sat, 01 Dec 2018 12:37:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gT4WE-0005sZ-MZ for pgsql-general@arkaria.postgresql.org; Sat, 01 Dec 2018 12:37:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gT4WE-0005sR-AX for pgsql-general@lists.postgresql.org; Sat, 01 Dec 2018 12:37:10 +0000 Received: from mail-oi1-x243.google.com ([2607:f8b0:4864:20::243]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gT4WB-0004FU-IZ for pgsql-general@lists.postgresql.org; Sat, 01 Dec 2018 12:37:09 +0000 Received: by mail-oi1-x243.google.com with SMTP id v6so7129961oif.2 for ; Sat, 01 Dec 2018 04:37:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=gu6Bl2ysJ4NBrmfgkLWxqkb6jFvfKQLe0/Jy8POSeRY=; b=hO7IWTWwqEocmiOjnvQWzPDYe7ojfXsfzj3Y8mt4Unk5kl89pwB/Apdc8ip5zZKvAK SBgP2b9UslIxJsOARLw3wEiOc4gaW8Rj5Wfn9nEcKZ2JwHdvHoLTSwRWWplOgNZuyYuz gVGT0RavG1y+YIPhLxLLGxzbAnbxXs9Z93dwDtXQIxm0uH6eUmCkgh1ChweH2rgENcnZ oEXU0lSVI45tQO7UaJ2uQPM0/sa3x9RVAF6v/ukkbdeHLjDovO63MnYV6k0/dbe0gUXZ 0hkZZ5kxFP9825eazCyXBx92lbVwzEpJ/Zi2ZuByzIV23nNPffMnxe0hEjqgQDjLei4m tXJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=gu6Bl2ysJ4NBrmfgkLWxqkb6jFvfKQLe0/Jy8POSeRY=; b=SDn34yi+pmgF0h/0yizn7hhSIZMMr+C+lQaRaS0qMBrgUHnz+9PppIcIvpyTGKCXpS JpyhlRnxP6TIcTEOWauQbJ4LXp7QUcLNFfXGk4GT+TShejnfT86SfyKzbuydKdfSzKjO bjA1Rszq4kcYJ0PyVty8KB/vpJ79PxHS9xIEG3SZZsD4kItTpD1BPnmw1ci9JwVcDnGj ExDefYrwsqsCpIny6Wh65eyEiWKbW57fsvTzpIBefDstKNN/+U6cMIdCgRUzn2EJAJy9 mOzkH85ryZBJ71L4MyN/aa+H7zfx3vScobNkYkVuGJq9wj669WG5vIebxIj/kbBvKz5i k1tw== X-Gm-Message-State: AA+aEWa140hm2oIiWBK7CPWitH24vF83BaRvG5WLrmXmCO/9Ttzx0/Vd Tuxss6w+421+GDC7+eUaEvPEQdGB X-Google-Smtp-Source: AFSGD/WkBUraJX92UB7xvNbsW0V6mMngEuFtUkMSW15+96eB3jP94koTK9msP3Q6CqGGKWokJBehcQ== X-Received: by 2002:aca:1e17:: with SMTP id m23mr5817209oic.332.1543667826620; Sat, 01 Dec 2018 04:37:06 -0800 (PST) Received: from [192.168.1.10] (ip70-171-116-89.no.no.cox.net. [70.171.116.89]) by smtp.googlemail.com with ESMTPSA id m207sm3363965oig.2.2018.12.01.04.37.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Dec 2018 04:37:05 -0800 (PST) Subject: =?UTF-8?Q?Re:_Transition_Tables_doesn=c2=b4t_have_OID?= To: pgsql-general@lists.postgresql.org References: <1543666938082-0.post@n3.nabble.com> From: Ron Message-ID: <2121577b-0c08-4ab9-28a8-797a12f05d0f@gmail.com> Date: Sat, 1 Dec 2018 06:37:05 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <1543666938082-0.post@n3.nabble.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 12/01/2018 06:22 AM, PegoraroF10 wrote: > 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 ? Did you create MyTable WITH OIDS (or set default_with_oids on in postgresql.conf)? https://www.postgresql.org/docs/9.6/datatype-oid.html Also, https://www.postgresql.org/docs/9.6/runtime-config-compatible.html#GUC-DEFAULT-WITH-OIDS "The use of OIDs in user tables is considered deprecated, so most installations should leave this variable disabled. Applications that require OIDs for a particular table should specify WITH OIDS when creating the table." More importantly, https://wiki.postgresql.org/wiki/FAQ#What_is_an_OID.3F "OIDs are sequentially assigned 4-byte integers. Initially they are unique across the entire installation. However, the OID counter wraps around at 4 billion, and after that OIDs may be duplicated. It is possible to prevent duplication of OIDs within a single table by creating a unique index on the OID column (but note that the WITH OIDS clause doesn't by itself create such an index). The system checks the index to see if a newly generated OID is already present, and if so generates a new OID and repeats. This works well so long as no OID-containing table has more than a small fraction of 4 billion rows." -- Angular momentum makes the world go 'round.