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


총 게시물 94건, 최근 0 건
   

오브젝트명의 대소문자 구분

글쓴이 : PostgresDBA 날짜 : 2013-06-22 (토) 17:35 조회 : 7218
PostgreSQL 에서는 디폴트로 object 명은 소문자화 하여 처리합니다.
오라클과는 반대지요

정말 그런지 확인해볼까요?

scott@[local]:5432:scottdb] 
SQL> select * from dept;
 deptno |   dname    |   loc    
--------+------------+----------
     10 | ACCOUNTING | NEW YORK
     20 | RESEARCH   | DALLAS
     30 | SALES      | CHICAGO
     40 | OPERATIONS | BOSTON
(4 rows)

scott@[local]:5432:scottdb] 
SQL> select * from DEPT;      -- DEPT 가 대문자지만 소문자화 합니다.
 deptno |   dname    |   loc    
--------+------------+----------
     10 | ACCOUNTING | NEW YORK
     20 | RESEARCH   | DALLAS
     30 | SALES      | CHICAGO
     40 | OPERATIONS | BOSTON
(4 rows)

scott@[local]:5432:scottdb] 
SQL> select * from Dept;
 deptno |   dname    |   loc    
--------+------------+----------
     10 | ACCOUNTING | NEW YORK
     20 | RESEARCH   | DALLAS
     30 | SALES      | CHICAGO
     40 | OPERATIONS | BOSTON
(4 rows)

scott@[local]:5432:scottdb] 
SQL> select * from "Dept";       -- double quote 를 쓸때는 대소문자를 구분합니다.
ERROR:  relation "Dept" does not exist
LINE 1: select * from "Dept";
                      ^
scott@[local]:5432:scottdb] 
SQL> select * from "DEPT";
ERROR:  relation "DEPT" does not exist
LINE 1: select * from "DEPT";
                      ^
scott@[local]:5432:scottdb] 
SQL> select * from "dept";       -- 소문자화 했더니 이때는 에러가 안나네요!!
 deptno |   dname    |   loc    
--------+------------+----------
     10 | ACCOUNTING | NEW YORK
     20 | RESEARCH   | DALLAS
     30 | SALES      | CHICAGO
     40 | OPERATIONS | BOSTON
(4 rows)

scott@[local]:5432:scottdb] 
SQL> 

내친김에 double quote 에 대해 알아봅시다.

scott@[local]:5432:scottdb] 
SQL> create table "SuperMan"(x smallint);    -- double quote 를 쓰면 대소문자를 구분합니다!
CREATE TABLE
scott@[local]:5432:scottdb] 
SQL> select * from SuperMan;
ERROR:  relation "superman" does not exist
LINE 1: select * from SuperMan;
                      ^
scott@[local]:5432:scottdb] 
SQL> select * from superman;
ERROR:  relation "superman" does not exist
LINE 1: select * from superman;
                      ^
scott@[local]:5432:scottdb] 
SQL> select * from "SuperMan";
 x 
---
(0 rows)

scott@[local]:5432:scottdb] 
SQL> select quote_ident('SuperMan');  -- 이런 재밌는 항수가 존재합니다.
 quote_ident 
-------------
 "SuperMan"
(1 row)

scott@[local]:5432:scottdb] 
SQL> 

   

postgresdba.com