반응형
/********************************************************************************************
-- Title : [PGS9.2] Usage of GREATEST and LEAST
-- Reference : postgresql.org
-- Key word : greatest lest min max
********************************************************************************************/
-- initiate table
drop table ttt;

-- create table
create table ttt
(a int, b varchar(100));

-- insert data
insert into ttt
select generate_series, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
from generate_series(1,1000, 1);

-- samples
select greatest(a, 100, null), least(a, 100, null)
from ttt;

select greatest(1,2,3,4,5,null), least(2,3,4,null, 5)
     , greatest(null, null), least(null, null)

select greatest(1, 'aaa');   -- occur error!
select greatest('aaa', 'bbb'), least('aaa', 'bbb');






반응형

+ Recent posts