SQL_CALC_FOUND_ROWS equivalent in PostgreSQL
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 totalWhat 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的更多相关文章
- PostgreSQL JSON函数
https://www.postgresql.org/docs/9.6/static/functions-json.html PostgreSQL 9.6.1 Documentation Prev U ...
- Ways to access Oracle Database in PostgreSQL
Today, organizations stores information(data) in different database systems. Each database system ha ...
- PostgreSQL index types and index bloating
warehouse_db=# create table item (item_id integer not null,item_name text,item_price numeric,item_da ...
- PostgreSQL中initdb做了什么
在使用数据库前,是启动数据库,启动数据库前是initdb(初始化数据库):一起来看一下initdb做了什么吧. 初始化数据库的操作为: ./initdb -D /usr/local/pgsql/dat ...
- Understanding postgresql.conf : log*
After loooong pause, adding next (well, second) post to the “series“. This time, I'd like to describ ...
- LINQ to PostgreSQL Tutorial
原文 LINQ to PostgreSQL Tutorial This tutorial guides you through the process of creating a simple app ...
- pg_dump实例详解(备份postgresql和greenplum数据库)
一.pg_dump的用法:数据库的导入导出是最常用的功能之一,每种数据库都提供有这方面的工具,例如Oracle的exp/imp,Informix的dbexp/dbimp,MySQL的mysqldump ...
- postgresql数据库的数据导出
一.pg_dump的用法:数据库的导入导出是最常用的功能之一,每种数据库都提供有这方面的工具,例如Oracle的exp/imp,Informix的dbexp/dbimp,MySQL的mysqldump ...
- 使用PostgreSQL进行全文检索
* { color: #3e3e3e } body { font-family: "Helvetica Neue", Helvetica, "Hiragino Sans ...
随机推荐
- 使用 WTForms 进行表单验证的例子
#使用 WTForms 进行表单验证的例子 from wtforms import Form from wtforms import BooleanField from wtforms import ...
- SpringBoot: 配置加载顺序
在应用程序中各种配置是不可避免的,Spring中对配置的抽象(Environment)可以说是达到了极致,其中有一项尤为突出:PropertySource(配置来源),配置来源通常包括命令行参数,系统 ...
- vue基础特性
在这里我们主要是讲解一些vue实例的属性和一些基础的指令 vue实例属性: 其实和我们之前所学的对象的属性是相似的东西 vue的基础指令: 对于指令,大家可能之前么有接触过相关的概念,其实大家可以这样 ...
- 一篇文章说透Nginx的rewrite模块
rewrite模块即ngx_http_rewrite_module模块,主要功能是改写请求URI,是Nginx默认安装的模块.rewrite模块会根据PCRE正则匹配重写URI,然后发起内部跳转再匹配 ...
- javaIO流--Writer,Reader
Writer /** *<li> Writer中定义的一个重要的方法: * public void writer(String str)throws IOException; */ pac ...
- ASP.NET Core + Docker + Jenkins + gogs + CentOS 从零开始搭建持续集成
为什么不用gitlab? 没有采用gitlab,因为gitlab比较吃配置,至少得2核4G的配置.采用go语言开发的gogs来代替,搭建方便(不到10分钟就能安装完成),资源消耗低,功能也比较强大,也 ...
- Vue2.0父子组件之间的双向数据绑定问题解决方案
对于vue 1.0项目代码,如果把vue换成vue 2.0,那么之后项目代码就完全奔溃不能运行,vue 2.0在父子组件数据绑定的变化(不再支持双向绑定)颠覆了1.0的约定,很遗憾. 解决方案只有两种 ...
- testng执行多个suite
由于testng.xml中只能设置一个<suite>标签,就无法创建多个测试集,通过<suite-files >标签可以实现允许多个测试集. 1.testng.xml中引入多个 ...
- 生成和配置https证书
最近在做小程序,调用后台接口需要https协议请求,小程序之所以这么要求,也是因为http协议是明文传播文件数据的,出于数据安全考虑,必须使用https协议. http想实现为https 就需要为配置 ...
- [HNOI 2015]开店
Description 风见幽香有一个好朋友叫八云紫,她们经常一起看星星看月亮从诗词歌赋谈到 人生哲学.最近她们灵机一动,打算在幻想乡开一家小店来做生意赚点钱.这样的 想法当然非常好啦,但是她们也发现 ...