postgres function: COALESCE

本文详细介绍了SQL标准函数COALESCE的用法,包括其如何返回非空值的第一个参数,以及如何用于替换数据检索过程中的NULL值。同时,提供了在不同环境下使用COALESCE函数的示例,并介绍了其与NVL、IFNULL等函数的相似性。最后,通过正则表达式的示例展示了如何在代码中高效地应用COALESCE函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

COALESCE


COALESCE(value [, ...])

The COALESCE function returns the first of its arguments that is not null. Null is returned only if all arguments are null. It is often used to substitute a default value for null values when data is retrieved for display, for example:

SELECT COALESCE(description, short_description, '(none)') ...

Like a CASE expression, COALESCE only evaluates the arguments that are needed to determine the result; that is, arguments to the right of the first non-null argument are not evaluated. This SQL-standard function provides capabilities similar to NVL and IFNULL, which are used in some other database systems.


TD中zeroifnull函数可用本函数替代:coalesce(arg,0),在notepad++中替换的正则表达式:

zeroifnull\(([\s\w\.]+)\)

替换为:

COALESCE(\1,0)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值