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

  • Home
  • SEARCH
  • 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 923151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:08:53+00:00 2026-05-15T19:08:53+00:00

Is it possible to see the last entry into a table that was triggered

  • 0

Is it possible to see the last entry into a table that was triggered on?

For instance, I have a table called “users” and a table called “log”. I want to write to “log” the userid that was last written to “users” so each time a user is created, it writes the userid to a log.

I create a trigger on users with a function like the one below…

CREATE OR REPLACE FUNCTION process_learner_creater() RETURNS TRIGGER AS $log$
BEGIN
IF (TG_OP = ‘INSERT’) THEN
INSERT INTO log SELECT userid from users;
RETURN NULL;
END IF;
RETURN NULL;
END;
$log$ LANGUAGE plpgsql;

So when an insert is fired onto the users table it will return the userid from users, the problem is I don’t know what was the last user to be added so this function will not work…

Is there a way to say…

INSERT INTO log SELECT <> from users;

This field in users would be a serial field so would auto-increment (and not be part of the the SQL script in the insert as this would be auto-assigned).

  • 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-15T19:08:53+00:00Added an answer on May 15, 2026 at 7:08 pm

    From what I understand, you want to use the NEW variable, which contains the new row for which the trigger was invoked (you don’t have to SELECT for it). Have you looked at the examples from the documentation?

    http://www.postgresql.org/docs/8.4/interactive/plpgsql-trigger.html

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

Sidebar

Related Questions

I am wondering if it is possible to see stored procs that are being
I see that in PL/SQL it is possible to set the session state of
Since VS 2005, I see that it is not possible to simply build a
So I have this website that has a search feature which searches a table
Let's say file.txt.gz has 2GB, and I want to see last 100 lines or
Is it possible to see the history of changes to a particular line of
Is it possible to see the return value of a method after the line
Is it possible in C# to see the traces in a separate console. For
Is it possible for me to see the amount of processor usage (% of
Is it possible to run a ruby application as a Windows Service? I see

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.