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. oracle11.2中分区功能测试之add&split partition对global&local index的影响

    生产库中某些大表的分区异常,需要对现有表进行在线操作,以添加丢失分区,因为是生产库,还是谨慎点好,今天有空,针对add&split分区对global&local索引的影响进行了测试,测 ...

  2. [LeetCode] Employee Free Time 职员的空闲时间

    We are given a list schedule of employees, which represents the working time for each employee. Each ...

  3. ftp爆破(python脚本)

    最近在乌云看到一份端口详解:为了锻炼自己,按照端口详解写脚本 #!/usr/local/bin/ python #-*- coding: UTF-8 -*- __author__ = '' from ...

  4. tarjan——cogs 1298 通讯问题

    1298. 通讯问题 ★   输入文件:jdltt.in   输出文件:jdltt.out   简单对比 时间限制:1 s   内存限制:128 MB [题目描述] 一个篮球队有n个篮球队员,每个队员 ...

  5. [HNOI2011]数矩形

    题目描述 最近某歌手在研究自己的全球巡回演出计划,他将所有心仪的城市都用平面上的一个点来表示,并打算从中挑选出 4 个城市作为这次巡回演出的地点. 为了显示自己与众不同,他要求存在一个矩形使得挑选出的 ...

  6. [JLOI2015]城池攻占

    题目描述 小铭铭最近获得了一副新的桌游,游戏中需要用 m 个骑士攻占 n 个城池.这 n 个城池用 1 到 n 的整数表示.除 1 号城池外,城池 i 会受到另一座城池 fi 的管辖,其中 fi &l ...

  7. [Cqoi2010]扑克牌

    Description 你有n种牌,第i种牌的数目为ci.另外有一种特殊的 牌:joker,它的数目是m.你可以用每种牌各一张来组成一套牌,也可以用一张joker和除了某一种牌以外的其他牌各一张组成1 ...

  8. 【HNOI2017】影魔

    题目描述 影魔,奈文摩尔,据说有着一个诗人的灵魂.事实上,他吞噬的诗人灵魂早已成千上万.千百年来,他收集了各式各样的灵魂,包括诗人.牧师.帝王.乞丐.奴隶.罪人,当然,还有英雄. 每一个灵魂,都有着自 ...

  9. ●BZOJ 3963 [WF2011]MachineWorks

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3963 题解: 斜率优化DP,CDQ分治. 先按时间排序.(规定以下内容的第i台机器的卖出时间 ...

  10. SPOJ 1812 Longest Common Substring II

    A string is finite sequence of characters over a non-empty finite set Σ. In this problem, Σ is the s ...