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 867947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:03:34+00:00 2026-05-15T10:03:34+00:00

I have a function that is used as an INSERT trigger. This function deletes

  • 0

I have a function that is used as an INSERT trigger. This function deletes rows that would conflict with [the serial number in] the row being inserted. It works beautifully, so I’d really rather not debate the merits of the concept.

DECLARE
re1 feeds_item.shareurl%TYPE;
BEGIN
SELECT regexp_replace(NEW.shareurl, '/[^/]+(-[0-9]+\.html)$','/[^/]+\\1') INTO re1;
RAISE NOTICE 'DELETEing rows from feeds_item where shareurl ~ ''%''', re1;

DELETE FROM feeds_item where shareurl ~ re1;
RETURN NEW;
END;

I would like to add to the NOTICE an indication of how many rows are affected (aka: deleted). How can I do that (using LANGUAGE ‘plpgsql’)?

UPDATE:
Base on some excellent guidance from “Chicken in the kitchen”, I have changed it to this:

DECLARE
re1 feeds_item.shareurl%TYPE;
num_rows int;
BEGIN
SELECT regexp_replace(NEW.shareurl, '/[^/]+(-[0-9]+\.html)$','/[^/]+\\1') INTO re1;

DELETE FROM feeds_item where shareurl ~ re1;
IF FOUND THEN
    GET DIAGNOSTICS num_rows = ROW_COUNT;
    RAISE NOTICE 'DELETEd % row(s) from feeds_item where shareurl ~ ''%''', num_rows, re1;
END IF;
RETURN NEW;
END;
  • 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-15T10:03:35+00:00Added an answer on May 15, 2026 at 10:03 am

    In Oracle PL/SQL, the system variable to store the number of deleted / inserted / updated rows is:

    SQL%ROWCOUNT
    

    After a DELETE / INSERT / UPDATE statement, and BEFORE COMMITTING, you can store SQL%ROWCOUNT in a variable of type NUMBER. Remember that COMMIT or ROLLBACK reset to ZERO the value of SQL%ROWCOUNT, so you have to copy the SQL%ROWCOUNT value in a variable BEFORE COMMIT or ROLLBACK.

    Example:

    BEGIN
       DECLARE
          affected_rows   NUMBER DEFAULT 0;
       BEGIN
          DELETE FROM feeds_item
                WHERE shareurl = re1;
    
          affected_rows := SQL%ROWCOUNT;
          DBMS_OUTPUT.
           put_line (
                'This DELETE would affect '
             || affected_rows
             || ' records in FEEDS_ITEM table.');
          ROLLBACK;
       END;
    END;
    

    I have found also this interesting SOLUTION (source: http://markmail.org/message/grqap2pncqd6w3sp )

    On 4/7/07, Karthikeyan Sundaram wrote:

    Hi,

    I am using 8.1.0 postgres and trying to write a plpgsql block.  In that I am inserting a row.  I want to check to see if the row has been
    

    inserted or not.

    In oracle we can say like this

    begin
      insert into table_a values (1);
      if sql%rowcount > 0
      then
        dbms.output.put_line('rows inserted');
      else
        dbms.output.put_line('rows not inserted');
     end if;  end;
    

    Is there something equal to sql%rowcount in postgres? Please help.

    Regards skarthi

    Maybe:

    http://www.postgresql.org/docs/8.2/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-SQL-ONEROW

    Click on the link above, you’ll see this content:

    37.6.6. Obtaining the Result Status There are several ways to determine the effect of a command. The first method is to use the GET
    DIAGNOSTICS command, which has the form:

    GET DIAGNOSTICS variable = item [ , … ];This command allows
    retrieval of system status indicators. Each item is a key word
    identifying a state value to be assigned to the specified variable
    (which should be of the right data type to receive it). The currently
    available status items are ROW_COUNT, the number of rows processed by
    the last SQL command sent down to the SQL engine, and RESULT_OID, the
    OID of the last row inserted by the most recent SQL command. Note that
    RESULT_OID is only useful after an INSERT command into a table
    containing OIDs.

    An example:

    GET DIAGNOSTICS integer_var = ROW_COUNT; The second method to
    determine the effects of a command is to check the special variable
    named FOUND, which is of type boolean. FOUND starts out false within
    each PL/pgSQL function call. It is set by each of the following types
    of statements:

    A SELECT INTO statement sets FOUND true if a row is assigned, false if
    no row is returned.

    A PERFORM statement sets FOUND true if it produces (and discards) a
    row, false if no row is produced.

    UPDATE, INSERT, and DELETE statements set FOUND true if at least one
    row is affected, false if no row is affected.

    A FETCH statement sets FOUND true if it returns a row, false if no row
    is returned.

    A FOR statement sets FOUND true if it iterates one or more times, else
    false. This applies to all three variants of the FOR statement
    (integer FOR loops, record-set FOR loops, and dynamic record-set FOR
    loops). FOUND is set this way when the FOR loop exits; inside the
    execution of the loop, FOUND is not modified by the FOR statement,
    although it may be changed by the execution of other statements within
    the loop body.

    FOUND is a local variable within each PL/pgSQL function; any changes
    to it affect only the current function.

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

Sidebar

Ask A Question

Stats

  • Questions 436k
  • Answers 436k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer something like $('.circle.runned').each(function(){ if($(this).offset().left + $(this).width < $('#wraper').offset().left || $(this).offset().left… May 15, 2026 at 3:56 pm
  • Editorial Team
    Editorial Team added an answer Try setting up your own proxy and connecting to it... May 15, 2026 at 3:56 pm
  • Editorial Team
    Editorial Team added an answer Methods that return void state more clearly that they have… May 15, 2026 at 3:56 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.