目次
機能の組み合わせ
1.concat
。文法入門
concat(str "any" [, str "any" [, ...]])
Concatenate all but first arguments with separators.
The first parameter is used as a separator.
NULL arguments are ignored.
。Bの実用的な例であります:
postgres=# create table t_kenyon(id int,name varchar(10),remark text);
CREATE TABLE
postgres=# insert into t_kenyon values(1,'test','kenyon'),(2,'just','china'),(3,'iam','lovingU');
INSERT 0 3
postgres=# insert into t_kenyon values(4,'test',null);
INSERT 0 1
postgres=# insert into t_kenyon values(5,null,'adele');
INSERT 0 1
postgres=# select * from t_kenyon;
id | name | remark
----+------+---------
1 | test | kenyon
2 | just | china
3 | iam | lovingU
4 | test |
5 | | adele
(5 rows)
postgres=# select concat(id,name,remark) from t_kenyon;
concat
-------------
1testkenyon
2justchina
3iamlovingU
4test
5adele
(5 rows)
C。説明
concat関数は、スプライシングの純粋関数である必要があれば、スプライシングは、区切り文字をヌル値、ノーモザイク区切り文字の値を無視することができ、次の機能CONCAT_WSを使用する必要があります。
2.concat_ws
。文法入門
concat_ws(sep text, str "any" [, str "any" [,...] ])
Concatenate all but first arguments with separators.
The first parameter is used as a separator.
NULL arguments are ignored.
B。実用化
postgres=# select concat_ws(',',id,name,remark) from t_kenyon;
concat_ws
---------------
1,test,kenyon
2,just,china
3,iam,lovingU
4,test
5,adele
(5 rows)
postgres=# select concat_ws('_',id,name,remark) from t_kenyon;
concat_ws
---------------
1_test_kenyon
2_just_china
3_iam_lovingU
4_test
5_adele
(5 rows)
postgres=# select concat_ws('',id,name,remark) from t_kenyon;
concat_ws
-------------
1testkenyon
2justchina
3iamlovingU
4test
5adele
(5 rows)
postgres=# select concat_ws('^_*',id,name,remark) from t_kenyon;
concat_ws
-------------------
1^_*test^_*kenyon
2^_*just^_*china
3^_*iam^_*lovingU
4^_*test
5^_*adele
(5 rows)
セパレータ機能の機能よりC. CONCAT_WS説明concat関数は、実際には、連結アップグレードされたバージョン、セパレータ「の場合は」、取り出し、結果は同じ連結です。CONCAT_WSセパレータも区切り文字として複数の文字をサポートし、毎日の使用は||である可能性が高いでした。
第二に、切断機能
1.split_part
。文法入門
split_part(string text, delimiter text, field int)
Split string on delimiter and return the given field (counting from one)
B。実際の例
postgres=# select split_part('abc~@~def~@~ghi','~@~', 2);
split_part
------------
def
(1 row)
postgres=# select split_part('now|year|month','|',3);
split_part
------------
month
(1 row)
Cに記載
の非常に効果的なセパレータを拾うために特定の場所によって関数値
2.regexp_split_to_table
。文法入門
regexp_split_to_table(string text, pattern text [, flags text])
Split string using a POSIX regular expression as the delimiter.
B。使用例
postgres=# SELECT regexp_split_to_table('kenyon,love,,china,!',',');
regexp_split_to_table
-----------------------
kenyon
love
china
!
(5 rows)
--按分割符切割
postgres=# SELECT regexp_split_to_table('kenyon, china loves',E'\\s');
regexp_split_to_table
-----------------------
kenyon,
china
loves
(3 rows)
--按字母切割
postgres=# SELECT regexp_split_to_table('kenyon,,china',E'\\s*');
regexp_split_to_table
-----------------------
k
e
n
y
o
n
,
,
c
h
i
n
a
(13 rows)
3.regexp_split_to_array
。文法入門
regexp_split_to_array(string text, pattern text [, flags text ])
Split string using a POSIX regular expression as the delimiter.
B。実際の例
postgres=# SELECT regexp_split_to_array('kenyon,love,,china,!',',');
regexp_split_to_array
--------------------------
{kenyon,love,"",china,!}
(1 row)
postgres=# SELECT regexp_split_to_array('kenyon,love,,china!','s*');
regexp_split_to_array
-----------------------------------------------
{k,e,n,y,o,n,",",l,o,v,e,",",",",c,h,i,n,a,!}
(1 row)
Cに記載
S *は、すべての分割を示している場所の上に使用されるフラグを、E「\\ s」はその逃げ空間を示し
3:複数行の結果が追加されます
GROUP_CONCAT(フィールド)
xxxxxtableからGROUP_CONCAT(ID)を選択し
注:この機能は、1024のデフォルトの制限の結果であります
SQLで見ることができます:「group_concat_max_len」のようなショーの変数。
文によって一時的に変更することができますが、それは、再起動後に再開
SET GLOBAL group_concat_max_len = 4294967295;
SET SESSION group_concat_max_len = 4294967295;