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. Python3NumPy——数组(2)之数学空间与NumPy空间

    0 介绍 本文承接上一篇,文章采用新的阐述方式,将数学中的表达与NumPy中的函数关联起来. 采用这种方式,可以直接建立数学表达与计算系统的对应关系,更易理解. 由于博客编写时间有限,每次尝试一个知识 ...

  2. iframe 里的高度自适应

    由于公司里的很多东西都要用到iframe 导致我不得不各种百度 首先是自适应高度 // document.domain = "caibaojian.com"; function s ...

  3. JDK安装、变量、变量的分类

    Lesson One 2018-04-17  19:50:35 JAVA语言特点: 编译型.强类型语言. 纯面向对象的语言,所有的代码都必须包含在class中的方法中 配置JAVA环境变量 1.安装J ...

  4. 前端小白想要编写可维护的js

    我是一名前端小白,之前没写过多少代码,心里没有代码质量这个概念,人人都说代码是团队的产物,应该将代码写规范,但是我对具体什么样的代码是可维护的是茫然的. 我没写过多少代码,本来好多东西就不咋会,每次给 ...

  5. Ubuntu重装mysql错误解决

    新搭建的服务器,先在Ubuntu上安装mariadb,后来由于很多权限问题,决定安装Mysql,在卸载过程中由于未卸载干净,导致mysql重装过程中出现了很多问题. Reading package l ...

  6. MQTT客户端库-Paho GO

    为了加深理解,本文是翻译文章.原文地址 Paho GO Client   语言 GO 协议 EPL AND EDL 官网地址 http://www.eclipse.org/paho/ API类型 As ...

  7. [Codeforces 919F]A Game With Numbers

    Description 题库链接 两个人 Van♂ 游戏,每人手上各有 \(8\) 张牌,牌上数字均为 \([0,4]\) 之间的数.每个人在自己的回合选自己手牌中数字不为 \(0\) 的一张与对方手 ...

  8. [BZOJ 5055]膜法师

    Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇宙的膜法师,想偷取其中的三个维度为伟大的长者续秒, 显然,他能为长者所续的时间,为这三个维度上能量的乘 ...

  9. codefroces 612E Square Root of Permutation

    A permutation of length n is an array containing each integer from 1 to n exactly once. For example, ...

  10. bzoj 2436: [Noi2011]Noi嘉年华

    Description NOI2011 在吉林大学开始啦!为了迎接来自全国各地最优秀的信息学选手,吉林大学决定举办两场盛大的 NOI 嘉年华活动,分在两个不同的地点举办.每个嘉年华可能包含很多个活动, ...