PostgreSQL octet_lengthメソッドで文字列のバイト数を取得する

環境
Windows 10 home 64bit
PostgreSQL 9.6

構文
SELECT OCTET_LENGTH(文字列)
OCTET_LENGTH関数を使用して文字列のバイト数を取得します。

使用例
SQL構文1
select octet_length('arkgame’) result;
実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
postgres=# select octet_length('arkgame') result;
result
--------
7
(1)
postgres=# select octet_length('arkgame') result; result -------- 7 (1 行)
postgres=# select octet_length('arkgame') result;
 result
--------
      7
(1 行)

SQL構文2
select octet_length('アイウえお’);
半角カタカナも1文字3バイトで計算します。

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
postgres=# select octet_length('アイウえお');
octet_length
--------------
15
(1)
postgres=# select octet_length('アイウえお'); octet_length -------------- 15 (1 行)
postgres=# select octet_length('アイウえお');
 octet_length
--------------
           15
(1 行)

 

PostgreSQL

Posted by arkgame