PostgreSQL 13にconcat関数で文字列を結合する

2022年1月8日

環境
Windows10 64 bit
PostgreSQL 13.2

書式
concat(文字列1,xxx)

使用例1
英字文字列を結合します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
postgres=# select concat('study','skill') result;
result
------------
studyskill
(1)
postgres=# select concat('study','skill') result; result ------------ studyskill (1 行)
postgres=# select concat('study','skill') result;
   result
------------
 studyskill
(1 行)

使用例2
文字列とnullを結合します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
postgres=# select concat('study',null,'skill') result;
result
------------
studyskill
(1)
postgres=# select concat('study',null,'skill') result; result ------------ studyskill (1 行)
postgres=# select concat('study',null,'skill') result;
   result
------------
 studyskill
(1 行)

使用例3
「||」で文字列とnullと結合するとnullになります

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
postgres=# select 'study' || 'skill' || null result;
result
--------
(1)
postgres=# select 'study' || 'skill' || null result; result -------- (1 行)
postgres=# select 'study' || 'skill' || null result;
 result
--------

(1 行)

 

PostgreSQL

Posted by arkgame