1、concat(拼接字段)
postgres=# select concat(id,name,remark) from t_kenyon;
concat
-------------
1testkenyon
2justchina
3iamlovingU
4test
5adele
2、concat_ws(拼接字段带拼接符)
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
3、split_apart(分割字段)
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)
4、cast(类型转换)
cast(aa as varchar)
5、coalesce(返回参数中的第一个非null的值,即将null赋值成某个定义字符)
select case when coalesce(name,'') = '' then '姓名为空' else name end from student;
6、case when(条件判断)
SELECT a,
CASE WHEN a=1 THEN 'one'
WHEN a=2 THEN 'two'
ELSE 'other'
END
FROM test;
a | case
---+-------
1 | one
2 | two
3 | other
---------------------