Developer
[PostgreSQL] schema 생성 및 조회설정
rocksea
2013. 6. 4. 18:54
postgresql schema 생성 및 조회설정.
step1. schema 생성
스키마 생성
CREATE SCHEMA myschema;
schema내 table 접근시
schema.table
다른 사용자가 소유한 스키마를 생성할 경우에는
CREATE SCHEMA schemaname AUTHORIZATION username;
step2. table 생성
CREATE TABLE products ( ... );
OR ( Database의 Default Schema가 Public이다.)
CREATE TABLE public.products ( ... );
step3. 조회 schema 보기
기본적으로 조회되는 스키마에대한 순서와 조회될 스키마를 추가 할 수 있다.
조회 후 test 스키마를 조회 경로에 추가한다.
$ sudo -u postgres psql -Upostgres -W test
test=# show search_path;
search_path
----------------
"$user",public
(1 row)
test=# create schema test;
CREATE SCHEMA
test=# ALTER USER postgres SET search_path = test,public;
test=# show search_path;
search_path
-------------
test, public
(1 row)
위와 같이 test schema를 우선적으로 지정했다면 (test, public)
조회시 public이 우선조회되는게 아니라 test schema가 우선순위로 지정되어 먼저 조회의 대상이 된다.
참고 URL : http://www.postgresql.org/docs/8.1/static/ddl-schemas.html
.by rockesa