Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql concat列,如果列为NULL或为空字符串,则跳过列_Sql_Database_String_Postgresql_Sql Null - Fatal编程技术网

Postgresql concat列,如果列为NULL或为空字符串,则跳过列

Postgresql concat列,如果列为NULL或为空字符串,则跳过列,sql,database,string,postgresql,sql-null,Sql,Database,String,Postgresql,Sql Null,我试图连接许多列,如果postgres中的列为NULL或空,则跳过该列。例如: SELECT CONCAT(coalesce('a',''), '|',coalesce('b',''), '|',coalesce(NULL,''), '|',coalesce('',''), '|',coalesce('',''), '|',coalesce('c','')) AS finalstring; 输出:a | b | |

我试图连接许多列,如果postgres中的列为NULL或空,则跳过该列。例如:

SELECT CONCAT(coalesce('a',''),
        '|',coalesce('b',''),
        '|',coalesce(NULL,''),
        '|',coalesce('',''),
        '|',coalesce('',''),
        '|',coalesce('c','')) AS finalstring;
输出:a | b | | | c

预期输出:a | b | c

使用,忽略空值:

如果还要忽略空字符串,则可以在以下情况下使用null:

使用,忽略空值:

如果还要忽略空字符串,则可以在以下情况下使用null:

相关的:相关的:
concat_ws('|', col1, col2, col3, ...) 
concat_ws('|', nullif(col1, ''), nullif(col2, ''), nullif(col3, ''), ...)