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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:03:48+00:00 2026-05-16T01:03:48+00:00

everybody using mysql knows: SELECT SQL_CALC_FOUND_ROWS ….. FROM table WHERE … LIMIT 5, 10;

  • 0

everybody using mysql knows:

SELECT SQL_CALC_FOUND_ROWS ..... FROM table WHERE ...  LIMIT 5, 10;

and right after run this :

SELECT FOUND_ROWS();

how do i do this in postrgesql? so far, i found only ways where i have to send the query twice…

  • 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-16T01:03:49+00:00Added an answer on May 16, 2026 at 1:03 am

    No, there is not (at least not as of July 2007). I’m afraid you’ll have to resort to:

    BEGIN ISOLATION LEVEL SERIALIZABLE;
    
    SELECT id, username, title, date FROM posts ORDER BY date DESC LIMIT 20;
    SELECT count(id, username, title, date) AS total FROM posts;
    
    END;
    

    The isolation level needs to be SERIALIZABLE to ensure that the query does not see concurrent updates between the SELECT statements.

    Another option you have, though, is to use a trigger to count rows as they’re INSERTed or DELETEd. Suppose you have the following table:

    CREATE TABLE posts (
        id      SERIAL PRIMARY KEY,
        poster  TEXT,
        title   TEXT,
        time    TIMESTAMPTZ DEFAULT now()
    );
    
    INSERT INTO posts (poster, title) VALUES ('Alice',   'Post 1');
    INSERT INTO posts (poster, title) VALUES ('Bob',     'Post 2');
    INSERT INTO posts (poster, title) VALUES ('Charlie', 'Post 3');
    

    Then, perform the following to create a table called post_count that contains a running count of the number of rows in posts:

    -- Don't let any new posts be added while we're setting up the counter.
    BEGIN;
    LOCK TABLE posts;
    
    -- Create and initialize our post_count table.
    SELECT count(*) INTO TABLE post_count FROM posts;
    
    -- Create the trigger function.
    CREATE FUNCTION post_added_or_removed() RETURNS TRIGGER AS $$
        BEGIN
            IF TG_OP = 'DELETE' THEN
                UPDATE post_count SET count = count - 1;
            ELSIF TG_OP = 'INSERT' THEN
                UPDATE post_count SET count = count + 1;
            END IF;
            RETURN NULL;
        END;
    $$ LANGUAGE plpgsql;
    
    -- Call the trigger function any time a row is inserted.
    CREATE TRIGGER post_added_or_removed_tgr
        AFTER INSERT OR DELETE
        ON posts
        FOR EACH ROW
        EXECUTE PROCEDURE post_added_or_removed();
    
    COMMIT;
    

    Note that this maintains a running count of all of the rows in posts. To keep a running count of certain rows, you’ll have to tweak it:

    SELECT count(*) INTO TABLE post_count FROM posts WHERE poster <> 'Bob';
    
    CREATE FUNCTION post_added_or_removed() RETURNS TRIGGER AS $$
        BEGIN
            -- The IF statements are nested because OR does not short circuit.
            IF TG_OP = 'DELETE' THEN
                IF OLD.poster <> 'Bob' THEN
                    UPDATE post_count SET count = count - 1;
                END IF;
            ELSIF TG_OP = 'INSERT' THEN
                IF NEW.poster <> 'Bob' THEN
                    UPDATE post_count SET count = count + 1;
                END IF;
            END IF;
            RETURN NULL;
        END;
    $$ LANGUAGE plpgsql;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 507k
  • Answers 507k
  • 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 The second approach looks like a SQL Server 2000 approach… May 16, 2026 at 4:05 pm
  • Editorial Team
    Editorial Team added an answer Are those acceptable settings for such an app? I'm asking… May 16, 2026 at 4:05 pm
  • Editorial Team
    Editorial Team added an answer In case anyone else needs the answer to this question… May 16, 2026 at 4:05 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

Related Questions

I just started creating my data-access layer using LinqToSql. Everybody is talking about the
I'm in a position where I'm the only one using git, everybody else is
As everybody working with Oracle knows, it an empty Varchar2 will result in a
I've got a database using DECIMAL type values for various tests on crude oil.
Ctrl + F11 is the Run keyboard shortcut in Eclipse. But for me, that
Hye Everybody I faced a problem when deploying solr on jboss . I wanted
I am creating breakpoints to debug my java application , and am using netbeans
My datawarehouse table just contains a single date SQL column, but I want to
HI Everybody I wanted to use caching in my application can any one help
I know I'll get a thousand Depends on what you're trying to do answers,

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.