博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
length() between oracle and postgresql
阅读量:2505 次
发布时间:2019-05-11

本文共 1710 字,大约阅读时间需要 5 分钟。

在读pg的doc 的时候, value  storage 的时候顺手测试了一下示例数据,结果就出问题了
PostgreSQL:digoal=> create table char_test(info char(20));
CREATE TABLE
digoal=> insert into char_test  values ('abcdef');
INSERT 0 1
digoal=> select info,length(info) from char_test ;
         info         | length 
----------------------+--------
 abcdef               |      6
(1 row)
而 doc 文档里的结果为 length 为 20 
难道是文档错误??
在oracle 里做了测试确实是20 。
Oracle:
SQL> create table char_test (info char(20));
Table created.
SQL> insert into char_test values ('abcdef');
1 row created.
SQL> select info,length(info) from char_test;
INFO                 LENGTH(INFO)
-------------------- ------------
abcdef                         20
一时很郁闷!!
找找资料解决问题: 
看看两个数据库的函数解释。
Oracle :
The LENGTH functions return the length of char. LENGTH calculates length using characters as defined by the input character set.
If char has datatype CHAR, then the length includes all trailing blanks. If char is null, then this function returns null.
PostgreSQL : 
length : 
Number of characters in string
显然PostgreSQL未计算blank字符的长度.
再看看PostgreSQL的HISTORY文件 : 确实有类似改动。
HISTORY:     * Add array_length() to return the length of an array for a specified
HISTORY:     * The length() function no longer counts trailing spaces in CHAR(n)
HISTORY:     * Make length() disregard trailing spaces in CHAR(n) (Gavin)
HISTORY:       counted by length().
HISTORY:     * The function "octet_length()" now returns the uncompressed data
HISTORY:     * New function bit_length() (Peter E)
HISTORY:     * Add pg_database_encoding_max_length() (Tatsuo)
HISTORY:Make char_length()/octet_length including trailing blanks (Tom)
问题终于搞清楚了 文档错误了
我顺便在文档里添加了一个comment  把pg 的history 加上了,这回不会误导人了。 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/133735/viewspace-706772/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/133735/viewspace-706772/

你可能感兴趣的文章
sdc时序约束
查看>>
Xilinx Jtag Access/svf文件/BSCANE2
查看>>
NoC片上网络
查看>>
开源SoC整理
查看>>
【2020-3-21】Mac安装Homebrew慢,解决办法
查看>>
influxdb 命令行输出时间为 yyyy-MM-dd HH:mm:ss(年月日时分秒)的方法
查看>>
已知子网掩码,确定ip地址范围
查看>>
判断时间或者数字是否连续
查看>>
docker-daemon.json各配置详解
查看>>
Docker(一)使用阿里云容器镜像服务
查看>>
Docker(三) 构建镜像
查看>>
FFmpeg 是如何实现多态的?
查看>>
FFmpeg 源码分析 - avcodec_send_packet 和 avcodec_receive_frame
查看>>
FFmpeg 新旧版本编码 API 的区别
查看>>
RecyclerView 源码深入解析——绘制流程、缓存机制、动画等
查看>>
Android 面试题整理总结(一)Java 基础
查看>>
Android 面试题整理总结(二)Java 集合
查看>>
学习笔记_vnpy实战培训day02
查看>>
学习笔记_vnpy实战培训day03
查看>>
VNPY- VnTrader基本使用
查看>>