length() between oracle and postgresql
在讀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 加上了,這回不會誤導人了。
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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Some difference between mysql & oracleMySqlOracle
- 20 Differences Between Oracle on NT and Oracle on UnixOracle
- Export And Import Between Different Oracle VersionsExportImportOracle
- postgresql中常用的函式:length、concat、as、substring、randomSQL函式random
- 20 Differences Between Oracle on NT and Oracle on Unix(Metalink:45967.1)Oracle
- 【Oracle】-Difference between Instance recovery and Crash RecoveryOracle
- PostgreSQL DBA(109) - pgAdmin(Don't do this:Don't use BETWEEN)SQL
- mysql char_length和lengthMySql
- 【Oracle SQL】months_between與trunc函式OracleSQL函式
- Java中 length、length()、size()區別Java
- PostgreSQL/Citus 常見報錯問題分析(一)ERROR: direct joins between distributedSQLError
- PostgreSQL DBA(114) - pgAdmin(Don't use char(n) even for fixed-length id)SQL
- oracle 匯入報錯:field in data file exceeds maximum lengthOracle
- oracle 獲取字串長度函式length()和lengthb()Oracle字串函式
- oracle取字串長度的函式length()和hengthb()Oracle字串函式
- DataTransferItemList.length
- sessionStorage.lengthSession
- CSSStyleDeclaration.lengthCSS
- inverse of arc length
- Oracle vs PostgreSQL DBA(21)- Oracle VPDOracleSQL
- Diffrence Between delete and truncatedelete
- Relationship between BAPI and RFCAPI
- Client / Server / Interoperability Support Between Different Oracle Versions [ID 207303.1]clientServerOracle
- FileList length 屬性
- CSSStyleDeclaration length 屬性CSS
- jQuery length屬性jQuery
- MySQL History List LengthMySql
- Oracle OCP IZ0-053 Q14(? ?NLS_LENGTH_SEMANTICS)Oracle
- Oracle NTH_VALUE分析函式及ROWS BETWEEN UNBOUNDED PRECEDING AND子句Oracle函式
- Compatibility Matrix for Export And Import Between Different Oracle Versions [Video] [ID 132904.1]ExportImportOracleIDE
- Move users between domainsAI
- What is the difference between <%, <%=, <%# and -%> in ERB in Rails?AI
- sql語句 between-andSQL
- Transport of Tablespaces Between Databases (59)Database
- Oracle vs PostgreSQL Develop(18) - BooleanOracleSQLdevBoolean
- Oracle vs PostgreSQL Develop(15) - DISTINCT ONOracleSQLdev
- Oracle vs PostgreSQL Develop(17) - ARRAYOracleSQLdev
- PostgreSQL/Oracle 時間改成秒SQLOracle