Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6601465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:45:22+00:00 2026-05-25T18:45:22+00:00

I am trying to capture data changes on a table and am executing the

  • 0

I am trying to capture data changes on a table and am executing the following trigger function AFTER INSERT OR UPDATE as well as BEFORE UPDATE OR DELETE:

CREATE OR REPLACE FUNCTION cdc_test_function()
  RETURNS trigger AS
$BODY$
DECLARE op cdc_operation_enum;
BEGIN
    op = TG_OP;
    IF (TG_WHEN = 'BEFORE') THEN
        IF (TG_OP = 'UPDATE') THEN
            op = 'UPDATE_BEFORE';
        END IF;

        INSERT INTO cdc_test VALUES (DEFAULT, DEFAULT, op, DEFAULT, DEFAULT, OLD.*);
    ELSE
        IF (TG_OP = 'UPDATE') THEN
            op = 'UPDATE_AFTER';
        END IF;

        INSERT INTO cdc_test VALUES (DEFAULT, DEFAULT, op, DEFAULT, DEFAULT, NEW.*);
    END IF;

    RETURN NEW;
END;

My change table (CDC_TEST) is capturing everything properly and I can both INSERT and UPDATE records just fine in my TEST table. However, when I try to DELETE, it records the DELETE entry perfectly in CDC_TEST, but the record remains in my TEST table. If I disable the trigger, then I can DELETE from TEST just fine. Here is the code I used to create my tables as well as the code for my enum:

CREATE TABLE test
(
  test_id serial NOT NULL,
  value text NOT NULL,
  CONSTRAINT test_pkey PRIMARY KEY (test_id )
)

CREATE TABLE cdc_test
(
  cdc_test_id bigserial NOT NULL,
  cdc_timestamp timestamp with time zone DEFAULT now(),
  cdc_opeation cdc_operation_enum,
  cdc_user name DEFAULT "current_user"(),
  cdc_transaction_id bigint DEFAULT txid_current(),
  test_id integer,
  value text,
  CONSTRAINT cdc_test_pkey PRIMARY KEY (cdc_test_id )
)

CREATE TYPE cdc_operation_enum AS ENUM( 'DELETE', 'INSERT', 'UPDATE_BEFORE', 'UPDATE_AFTER', 'UPDATE' );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:45:22+00:00Added an answer on May 25, 2026 at 6:45 pm

    Return OLD when the trigger runs for a deletion, NEW for an update.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a test list that I am trying to capture data from using
I am trying to capture data from my form and pump it into a
I am trying to use grep to capture data below: \\.xy$ \\.ab$ \\.ef\\.hi$ I
I'm trying to capture a url like the following in an intent: https://example.com/apple/orange?key=value I've
I'm trying to capture data from a SysListView32 class (according to Spy++) from another
Consider following table. I'm trying to write a query to display - Max values
I'm trying to get the compressed JPEG data out of the Camera Capture UI,
I'm trying to figure out how to capture data from a form using EditText
I trying to capture packets using SharpPcap library. I'm able to return the packets
I am trying to capture output from an install script (that uses scp) and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.