79203564

Date: 2024-11-19 13:18:51
Score: 0.5
Natty:
Report link

Inspired by @daniel-l-vandenbosch, I'd prefer this one, without overloading ;-)

CREATE OR REPLACE FUNCTION iif(condition boolean, true_result anyelement, false_result anyelement)
    RETURNS anyelement
    LANGUAGE SQL
    IMMUTABLE PARALLEL SAFE AS
'SELECT CASE WHEN condition THEN true_result ELSE false_result END';

This is using ANYELEMENT instead of TEXT, so it should work with more datatypes without casting/conversion.

Also added immutable and parallel safe to improve performace.

Reasons:
  • Has code block (-0.5):
  • User mentioned (1): @daniel-l-vandenbosch
Posted by: frankhommers