web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Power Apps + Triggers ...
Power Apps
Suggested Answer

Power Apps + Triggers in PostgreSQL

(1) ShareShare
ReportReport
Posted on by 50
Hello there!
 
I am working with power apps, I have connected to a postgres database and inside my power apps I can add rows and update values from my database. Everything was goung good, until I tried to create a shadow table or an audit_table (so I could get the information of changes made in the table). I was using the following queries in PostgreSQL:
 
CREATE TABLE shadow_table (
  id SERIAL PRIMARY KEY,
  original_id INT,
  original_data TEXT, -- or match the column structure of your main table
  operation VARCHAR(10), -- 'INSERT', 'UPDATE', 'DELETE'
  changed_at TIMESTAMP DEFAULT NOW(),
  changed_by VARCHAR(50) -- optional to track who made the change
);

CREATE OR REPLACE FUNCTION audit_changes()
RETURNS TRIGGER AS $$
BEGIN
  IF (TG_OP = 'INSERT') THEN
    INSERT INTO shadow_table (original_id, original_data, operation, changed_by)
    VALUES (NEW.id, row_to_json(NEW), 'INSERT', current_user);
  ELSIF (TG_OP = 'UPDATE') THEN
    INSERT INTO shadow_table (original_id, original_data, operation, changed_by)
    VALUES (NEW.id, row_to_json(NEW), 'UPDATE', current_user);
  ELSIF (TG_OP = 'DELETE') THEN
    INSERT INTO shadow_table (original_id, original_data, operation, changed_by)
    VALUES (OLD.id, row_to_json(OLD), 'DELETE', current_user);
  END IF;
  RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER audit_trigger
AFTER INSERT OR UPDATE OR DELETE ON primary_table
FOR EACH ROW EXECUTE FUNCTION audit_changes();
 
I thought this would work, but I got a conflict: now my power apps cannot add rows nor update values. I get a message of error but no more info than that.
 
Do you know how can I see the full error? Can you imagine what is going on? Is there a way to change my queries in order to have both things?
Categories:
I have the same question (0)
  • EddieE Profile Picture
    4,641 Moderator on at
    Powerapps doesn't work with SQL table which have Triggers setup. My guess is this is causing your issues.
     
    You can, however, now work directly with Stored Procedures, if that is an option?
  • Suggested answer
    RC-08052220-0 Profile Picture
    4 on at
    I have the same setup working.  Have you tried inserting into your primary table to check that the triggers are all working without Power Apps involved?
     
    If that is working fine, try setting up a Notify on the app's onError property: 
    Notify("An error occurred: " & FirstError.Message & " from the control: " & FirstError.Source, NotificationType.Error, 0);

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard