https://www.postgresql.org/message-id/1185863074.10580.91.camel%40linda.lfix.co.uk

On Tue, 2007-07-31 at 09:22 +0800, Matt Arnilo S. Baluyos (Mailing

Lists) wrote:

Hello everyone,

I would like to use PostgreSQL with the SmartyPaginate plugin of the

Smarty template engine.

In the examples on the documentation, the following two queries are used:

SELECT SQL_CALC_FOUND_ROWS * FROM mytable LIMIT X,Y

SELECT FOUND_ROWS() as total

What the SQL_CALC_FOUND_ROWS does is that it allows the FOUND_ROWS()

function to return the total rows if the first query didn't have the

LIMIT.

SQL_CALC_FOUND_ROWS and FOUND_ROWS() are MySQL features.

Is there an equivalent function in PostgreSQL for this or perhaps a

workaround?

There is no equivalent. Use

BEGIN;

SELECT * FROM mytable OFFSET X LIMIT Y;

SELECT COUNT(*) AS total FROM mytable;

END;

(To ensure consistent results, both queries should be done in a single

transaction.)

If you are repeating the query multiple times for separate pages, it

would be more efficient to do the COUNT() selection first and not repeat

it for each page. You could use a cursor to go back and forth through

the results while doing the query only once.

SQL_CALC_FOUND_ROWS equivalent in PostgreSQL的更多相关文章

  1. PostgreSQL JSON函数

    https://www.postgresql.org/docs/9.6/static/functions-json.html PostgreSQL 9.6.1 Documentation Prev U ...

  2. Ways to access Oracle Database in PostgreSQL

    Today, organizations stores information(data) in different database systems. Each database system ha ...

  3. PostgreSQL index types and index bloating

    warehouse_db=# create table item (item_id integer not null,item_name text,item_price numeric,item_da ...

  4. PostgreSQL中initdb做了什么

    在使用数据库前,是启动数据库,启动数据库前是initdb(初始化数据库):一起来看一下initdb做了什么吧. 初始化数据库的操作为: ./initdb -D /usr/local/pgsql/dat ...

  5. Understanding postgresql.conf : log*

    After loooong pause, adding next (well, second) post to the “series“. This time, I'd like to describ ...

  6. LINQ to PostgreSQL Tutorial

    原文 LINQ to PostgreSQL Tutorial This tutorial guides you through the process of creating a simple app ...

  7. pg_dump实例详解(备份postgresql和greenplum数据库)

    一.pg_dump的用法:数据库的导入导出是最常用的功能之一,每种数据库都提供有这方面的工具,例如Oracle的exp/imp,Informix的dbexp/dbimp,MySQL的mysqldump ...

  8. postgresql数据库的数据导出

    一.pg_dump的用法:数据库的导入导出是最常用的功能之一,每种数据库都提供有这方面的工具,例如Oracle的exp/imp,Informix的dbexp/dbimp,MySQL的mysqldump ...

  9. 使用PostgreSQL进行全文检索

    * { color: #3e3e3e } body { font-family: "Helvetica Neue", Helvetica, "Hiragino Sans ...

随机推荐

  1. JavaScript的屏幕对象

    screen 屏幕对象 反映了当前用户的屏幕设置. width 返回屏幕的宽度(像素数). height 返回屏幕的高度. availWidth 返回屏幕的可用宽度(除去了一些不自动隐藏的类似任务栏的 ...

  2. Windows下使用console线连接思科交换机

    在XP下可以直接使用内置工具"超级终端",在win7或者更高版本需要下载安装SecureCRT. 本文假设已经下载安装好了SecureCRT. 首先,将电脑连接console线.因 ...

  3. 华为防火墙USG5500-企业双ISP出口

    需求:(1)技术部IP地址自动获取,网段为192.168.10.0/24,该部门访问Internet的报文正常情况下流入链路ISP1. 总经办IP地址自动获取,网段为192.168.20.0/24,该 ...

  4. Java入门2

    一.Arrays工具类 1.数组地址的比较 int [] arr1={1,2,3,4,5}; int [] arr2={1,2,3,4,5}; System.out.println(arr1==arr ...

  5. jqurey datatables属性

    $('selector').dataTable( { /* * 默认为true * 是否自动计算列宽,计算列宽会花费一些时间,如果列宽通过aoColumns传递,可以关闭该属性作为优化 */ &quo ...

  6. PHP性能优化利器:生成器 yield理解

    如果是做Python或者其他语言的小伙伴,对于生成器应该不陌生.但很多PHP开发者或许都不知道生成器这个功能,可能是因为生成器是PHP 5.5.0才引入的功能,也可以是生成器作用不是很明显.但是,生成 ...

  7. mysql用limit时offset越大时间越长

    首先说明一下MySQL的版本:mysql> select version();+-----------+| version() |+-----------+| 5.7.17    |+----- ...

  8. [LeetCode] Find Mode in Binary Search Tree 找二分搜索数的众数

    Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred ...

  9. Java面试题—初级(7)

    作为一枚Java后端开发者,数据库知识必不可少,对数据库的掌握熟悉度的考察也是对这个人是否有扎实基本功的考察.特别对于初级开发者,面试可能不会去问框架相关知识,但是绝对不会不去考察数据库知识,这里收集 ...

  10. 想进大厂,想收获高薪offer,资深猎头告诉你怎么做......

    其实吧,面试官面试的时候主要就看三个方面:现在能力如何,未来潜力如何,人品如何. 第一个因素是最重要的,因为后面两个因素有太多的人为判断因素,无法量化.所谓的面试准备,"现在能力如何&quo ...