설문조사
PostgreSQL/PPAS 관련 듣고 싶은 교육은


총 게시물 94건, 최근 0 건
   

empty string('') 과 NULL (오라클 사용자는 주의!!)

글쓴이 : PostgresDBA 날짜 : 2012-12-19 (수) 13:44 조회 : 7252
오라클에서는 ''(empty string) 과 NULL 은 동일합니다.
하지만 PostgreSQL 에서는 '' 은 절대 NULL 이 아닙니다.

아래 예제를 음미해보세요.

scott@pg-00:5432:scottdb] 
SQL> create table test(x varchar(10));
CREATE TABLE
Time: 19.392 ms
scott@pg-00:5432:scottdb] 
SQL> insert into test values(100);
INSERT 0 1
Time: 3.773 ms
scott@pg-00:5432:scottdb] 
SQL> insert into test values('superman');
INSERT 0 1
Time: 3.114 ms
scott@pg-00:5432:scottdb] 
SQL> insert into test values(NULL);
INSERT 0 1
Time: 24.423 ms
scott@pg-00:5432:scottdb] 
SQL> insert into test values('');
INSERT 0 1
Time: 2.443 ms
scott@pg-00:5432:scottdb] 
SQL> SELECT COUNT(*) FROM TEST where x is null;
 count 
-------
     1
(1 row)

Time: 5.301 ms
SQL> SELECT x  FROM TEST where x is not null;
    x     
----------
 100
 superman
                          <-- 눈에 안보이네요.
(3 rows)

Time: 1.022 ms
scott@pg-00:5432:scottdb] 
SQL> 

   

postgresdba.com