Returning of affected rows when executing postgresql function (stored procedure)

Posted on 2006-03-22
Last Modified: 2012-05-05

when executing a postgresql function/stored proc (like an update) I would like to have as return value the number of affected rows. Could someone, please, help me?


Question by:davyberroho
    LVL 22

    Accepted Solution


    create or replace function x returns integer is $$
      number_of_rows integer := 0;
      update table_y set col_x = default where col_z is null;
      GET DIAGNOSTICS number_of_rows = ROW_COUNT;
      return number_of_rows;
    $$ language plpgsql;
    LVL 61

    Expert Comment

    No comment has been added to this question in more than 21 days, so it is now classified as abandoned.
    I will leave the following recommendation for this question in the Cleanup topic area:

    Accept earthman2 http:#16261285

    Any objections should be posted here in the next 4 days. After that time, the question will be closed.

    EE Cleanup Volunteer

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Best database to use for Maps is PostgreSQL. This is an open source database. Comes as a package with most Linux OS. For more info visit the following site: ( This requires some add-o…
    Many developers have database experience, but are new to PostgreSQL. It has some truly inspiring capabilities. I have several years' experience with Microsoft's SQL Server. When I began working with MySQL, I wanted a quick-reference to MySQL (htt…
    Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
    This video discusses moving either the default database or any database to a new volume.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now