PostgresQL中的NUlls first/last功能
Nulls first/last功能简介
Nulls first/last功能主要用于order by排序子句中,影响空值Null在排序结果中的位置。简单来说,Nulls first表示Null值在排序时一直排在所有值的前面,也就是处理order by a desc时PostgresQL执行器认为Null值大于所有值,而order by a或order by a asc时执行器认为Null值小于所有值,将Null值排在前面。Nulls last表示Null值在排序时一直排在所有值的后面,也就是处理order by a desc时PostgresQL执行器认为Null值小于所有值,而order by a或order by a asc时执行器认为Null值大于所有值,将Null值排在前面。当不指定Nulls first/last功能时,执行器默认认为Null值要大于所有值,以此为依据处理order by子句的排序结果。
Nulls first/last功能简单展示
以下测试均为Postgres数据库下测试,数据库版本为9.2.2,测试系统为Linux。
普通表简单功能展示:
Create table test1(a int, b int);
Insertinto test1 values(1,2);
Insertinto test1 values(3,4);
Insertinto test1 values(5);
Select * from test1 order by b desc nulls first;
a b
5
3 4
1 2
Select * from test1 order by b desc nulls last;
a b
3 4
1 2
5
Select *from test1 order by b desc nulls; 报错
分区表简单功能展示,注意PostgresQL数据库建分区表的方式:
createtable test_hash(a int, b int);
createtable test_hash1(check(a>=0 and a<5)) inherits(test_hash);
createtable test_hash2(check(a>=5)) inherits(test_hash);
createrule test_hash_1 as on insert to test_hash where(a>=0 and a<5) do insteadinsert into test_hash1 values(NEW.a,NEW.b);
createrule test_hash_2 as on insert to test_hash where(a>=5) do instead insertinto test_hash2 values(NEW.a,NEW.b);
Insertinto test_hash values(1,2);
Insertinto test_hash values(3,4);
Insertinto test_hash values(5);
Select *from test_hash order by b desc nulls first;
a b
5
3 4
2 2
Select *from test_hash order by b desc nulls last;
a b
3 4
1 2
5
以上均是select语句中的order by子句进行的Nulls first/last功能展示,创建索引等其他需要order by子句的地方同理。这里只是简单的展示了一下功能,有时间会写一些剖析PostgresQL数据库的文章出来
PostgresQL中的NUlls first/last功能的更多相关文章
- PostgreSQL中的索引(一)
引言 这一系列文章主要关注PostgreSQL中的索引. 可以从不同的角度考虑任何主题.我们将讨论那些使用DMBS的应用开发人员感兴趣的事项:有哪些可用的索引:为什么会有这么多不同的索引:以及如何使用 ...
- Postgresql中临时表(temporary table)的特性和用法
熟悉Oracle的人,相比对临时表(temporary table)并不陌生,很多场景对解决问题起到不错的作用,开源库Postgresql中,也有临时表的概念,虽然和Oracle中临时表名字相同,使用 ...
- Postgresql中的数据类型大全
一.数值类型: 下面是PostgreSQL所支持的数值类型的列表和简单说明: 名字 存储空间 描述 范围 smallint 2 字节 小范围整数 -32768 到 +32767 integer 4 字 ...
- 用ArcMap在PostgreSQL中创建要素类需要执行”create enterprise geodatabase”吗
问:用Acmap在PostgreSQL中创建要素类需要执行"create enterprise geodatabase"吗? 关于这个问题,是在为新员工做postgresql培训后 ...
- PostgreSQL中定时job执行(pgAgent)
PostgreSQL中定时job执行 业务分析 近期项目需要定期清理数据库中的多余数据,即每月1号删除指定表中一年以上的数据. 初步分析这种定时job可以使用一下两种技术实现: Linux的cront ...
- 在PostgreSQL中 pg_start_backup 做了什么?
# 在PostgreSQL中 pg_start_backup 做了什么?HM 2019-07-30 ## pg_start_backup 做一个备份开始标记,还做了一些其他的操作,下面进行探寻. * ...
- 在PostgreSQL中CREATE STATISTICS
如果你用Postgres做了一些性能调优,你可能用过EXPLAIN.EXPLAIN向你展示了PostgreSQL计划器为所提供的语句生成的执行计划,它显示了语句所引用的表如何被扫描(使用顺序扫描.索引 ...
- 实现ABP中Person类的权限功能
菜单项的显示功能已经完全OK了.那么我们就开始制作视图功能吧. 首先测试接口是否正常 我们通过代码生成器将权限和application中大部分功能已经实现了.那么我们来测试下这些接口ok不. 浏览/a ...
- 通过arcgis在PostgreSQL中创建企业级地理数据库
部署环境: Win7 64位旗舰版 软件版本: PostgreSQL-9.1.3-2-windows-x64 Postgis-pg91x64-setup-2.0.6-1 Arcgis 10.1 SP1 ...
随机推荐
- 【Leetcode】Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...
- linux 底层 基础命令 路径信息
z基础命令: 打印 :echo "hello world“ 切换目录 cd / 显示当前路径 pwd 显示 目录下所有文件 ls 显示所有文件包括隐藏文件 ls ...
- ButterKnife 8.4注入失败
1,第一步:项目的gradle中增加 classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'buildscript { repositor ...
- Mock Server利器 - Moco
Moco介绍Moco独立运行所需环境如何运行Moco启动http服务启动https服务Moco HTTPs API配置如何在配置文件添加注释约定请求Body约定接口的uri约定请求参数约定请求方法约定 ...
- asp.net core 标签验证函数功能
public class AuthFilter : Attribute, IActionFilter { public void OnActionExecuted(ActionExecutedCont ...
- java中所有开源注解收集
@resource: resource全名为@Resource ,用来激活一个命名资源(namedresource)的依赖注入,在JavaEE应用程序中,该注解被典型地转换为绑定于JNDI conte ...
- ora-1652
###检查是否有temp 在使用 step 2: 检查是否有事务使用到temp,并且进行删除. SELECT vt.inst_id,vs.sid,vs.serial#,vs.username,vs.o ...
- 研磨设计模式学习笔记4--单例模式Signleton
需求:加载配置文件,由于配置文件全局唯一,所以不用过多对象,建一个就可以了. 优点:单例模式本质就是为了控制实例数目. 一.饿汉式 public class Singleton { private S ...
- JavaSE---死锁
1.死锁: 当2个线程互相等待对方释放 同步监视器 时就会发生死锁,JVM没有监测,也没有采取任何措施来避免死锁(当出现死锁时,整个程序既不会发生任何异常,也不会有任何提示, 所有线程处于阻塞状态 ...
- oracle_expdp_help
[oracle@ctp ~]$ expdp -help Export: Release 11.2.0.3.0 - Production on Thu Feb 28 13:52:15 2019 Copy ...