expressions

InHwa Hong·2023년 6월 30일
0

| https://www.youtube.com/watch?v=HN_95ObHAiw&t=1698s

simple case expression

select n
     , case n
            when 1 then 'one'
            when 2 then 'two'
            else 'many'
        end as name
from (values 1,2,3,4) as t(n)


searched case expression

select n
     , case 
            when n = 1 then 'a'
            when n in (2,3) then 'b'
            else 'c'
        end as name
from (values 1,2,3,4) as t(n)


if expression


try expression

  • try avoids failures below
-- 에러 발생 
select 
    8/0 as div_zero,  					-- DIVISION_BY_ZERO: / by zero
    cast('abc' as integer) as not_int,  -- INVALID_CAST_ARGUMENT: Cannot cast 'abc' to INT
    2000000000 + 2000000000 as overflow -- NUMERIC_VALUE_OUT_OF_RANGE: integer addition overflow

-- 무시하고 넘어가고 싶을 경우 try 함수 사용한다. 
select 
    try(8/0) as div_zero,  					
    try(cast('abc' as integer)) as not_int,  
    try(2000000000 + 2000000000) as overflow 

lambda expression

overview

lambda expression with one input : x -> x + 8
lambda expression with two inputs " (x,y) -> x+y

0개의 댓글