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


Powered by EnterpriseDB
총 게시물 71건, 최근 0 건
   

psql 의 내부 명령어 - 하편

글쓴이 : PostgresDBA 날짜 : 2012-12-15 (토) 00:47 조회 : 5448
[postgres@olmaster:~]$ psql -d scottdb -U scott -W
Password for user scott: 
Null display is "NULL".
Timing is on.
Pager is always used.
psql (9.2.1)
Type "help" for help.

scott@[local]:5432 scottdb#SQL> select * from emp;
 empno | ename  |    job    | mgr  |  hiredate  | sal  | comm | deptno 
-------+--------+-----------+------+------------+------+------+--------
  7369 | SMITH  | CLERK     | 7902 | 1980-12-17 |  800 | NULL |     20
  7499 | ALLEN  | SALESMAN  | 7698 | 1981-02-20 | 1600 |  300 |     30
  7521 | WARD   | SALESMAN  | 7698 | 1981-02-22 | 1250 |  500 |     30
  7566 | JONES  | MANAGER   | 7839 | 1981-04-02 | 2975 | NULL |     20
  7654 | MARTIN | SALESMAN  | 7698 | 1981-09-28 | 1250 | 1400 |     30
  7698 | BLAKE  | MANAGER   | 7839 | 1981-05-01 | 2850 | NULL |     30
  7782 | CLARK  | MANAGER   | 7839 | 1981-06-09 | 2450 | NULL |     10
  7788 | SCOTT  | ANALYST   | 7566 | 1982-12-09 | 3000 | NULL |     20
  7839 | KING   | PRESIDENT | NULL | 1981-11-17 | 5000 | NULL |     10
  7844 | TURNER | SALESMAN  | 7698 | 1981-09-08 | 1500 |    0 |     30
  7876 | ADAMS  | CLERK     | 7788 | 1983-01-12 | 1100 | NULL |     20
  7900 | JAMES  | CLERK     | 7698 | 1981-12-03 |  950 | NULL |     30
  7902 | FORD   | ANALYST   | 7566 | 1981-12-03 | 3000 | NULL |     20
  7934 | MILLER | CLERK     | 7782 | 1982-01-23 | 1300 | NULL |     10
(14 rows)

Time: 0.797 ms
scott@[local]:5432 scottdb#SQL> \w cmd.sql          -- 방금전의 수행한 쿼리를 화일로 저장
scott@[local]:5432 scottdb#SQL> \! cat cmd.sql           -- os 명령어 호출 
select * from emp;                                              쿼리가 잘 저장되었음을 확인할수 있음
scott@[local]:5432 scottdb#SQL> \o cmd.txt             -- 질의 결과를 cmd.txt 화일로 전송 
                                                                      오라클로 치면 spool cmd.txt
scott@[local]:5432 scottdb#SQL> \! cat cmd.txt
scott@[local]:5432 scottdb#SQL> select * from emp;
Time: 0.366 ms
scott@[local]:5432 scottdb#SQL> \! cat cmd.txt            -- 저장된 cmd.txt 화일의 내용출력
 empno | ename  |    job    | mgr  |  hiredate  | sal  | comm | deptno 
-------+--------+-----------+------+------------+------+------+--------
  7369 | SMITH  | CLERK     | 7902 | 1980-12-17 |  800 | NULL |     20
  7499 | ALLEN  | SALESMAN  | 7698 | 1981-02-20 | 1600 |  300 |     30
  7521 | WARD   | SALESMAN  | 7698 | 1981-02-22 | 1250 |  500 |     30
  7566 | JONES  | MANAGER   | 7839 | 1981-04-02 | 2975 | NULL |     20
  7654 | MARTIN | SALESMAN  | 7698 | 1981-09-28 | 1250 | 1400 |     30
  7698 | BLAKE  | MANAGER   | 7839 | 1981-05-01 | 2850 | NULL |     30
  7782 | CLARK  | MANAGER   | 7839 | 1981-06-09 | 2450 | NULL |     10
  7788 | SCOTT  | ANALYST   | 7566 | 1982-12-09 | 3000 | NULL |     20
  7839 | KING   | PRESIDENT | NULL | 1981-11-17 | 5000 | NULL |     10
  7844 | TURNER | SALESMAN  | 7698 | 1981-09-08 | 1500 |    0 |     30
  7876 | ADAMS  | CLERK     | 7788 | 1983-01-12 | 1100 | NULL |     20
  7900 | JAMES  | CLERK     | 7698 | 1981-12-03 |  950 | NULL |     30
  7902 | FORD   | ANALYST   | 7566 | 1981-12-03 | 3000 | NULL |     20
  7934 | MILLER | CLERK     | 7782 | 1982-01-23 | 1300 | NULL |     10
(14 rows)

scott@[local]:5432 scottdb#SQL> \o                 --- cmd.txt 로의 화일 쓰기를 중지
                                                                오라클로 치면 spool off
Time: 0.591 ms
scott@[local]:5432 scottdb#SQL> \H                 -- 출력 결과를 HTML 포맷으로 보여줌.
Output format is html.
scott@[local]:5432 scottdb#SQL> select * from emp limit 1;    -- html 형태로 결과가 나타남.
<table border="1">
  <tr>
    <th align="center">empno</th>
    <th align="center">ename</th>
    <th align="center">job</th>
    <th align="center">mgr</th>
    <th align="center">hiredate</th>
    <th align="center">sal</th>
    <th align="center">comm</th>
    <th align="center">deptno</th>
  </tr>
  <tr valign="top">
    <td align="right">7369</td>
    <td align="left">SMITH</td>
    <td align="left">CLERK</td>
    <td align="right">7902</td>
    <td align="left">1980-12-17</td>
    <td align="right">800</td>
    <td align="right">NULL</td>
    <td align="right">20</td>
  </tr>
</table>
<p>(1 row)<br />
</p>
Time: 0.543 ms
scott@[local]:5432 scottdb#SQL> \H       -- 다시 한번 수행하여 html 형식 출력 중지
Output format is aligned.
scott@[local]:5432 scottdb#SQL> \t        -- 컬럼 헤더 생략
Showing only tuples.
scott@[local]:5432 scottdb#SQL> select * from emp;  -- 쿼리 결과에 헤더가 안보임.
  7369 | SMITH  | CLERK     | 7902 | 1980-12-17 |  800 | NULL |     20
  7499 | ALLEN  | SALESMAN  | 7698 | 1981-02-20 | 1600 |  300 |     30
  7521 | WARD   | SALESMAN  | 7698 | 1981-02-22 | 1250 |  500 |     30
  7566 | JONES  | MANAGER   | 7839 | 1981-04-02 | 2975 | NULL |     20
  7654 | MARTIN | SALESMAN  | 7698 | 1981-09-28 | 1250 | 1400 |     30
  7698 | BLAKE  | MANAGER   | 7839 | 1981-05-01 | 2850 | NULL |     30
  7782 | CLARK  | MANAGER   | 7839 | 1981-06-09 | 2450 | NULL |     10
  7788 | SCOTT  | ANALYST   | 7566 | 1982-12-09 | 3000 | NULL |     20
  7839 | KING   | PRESIDENT | NULL | 1981-11-17 | 5000 | NULL |     10
  7844 | TURNER | SALESMAN  | 7698 | 1981-09-08 | 1500 |    0 |     30
  7876 | ADAMS  | CLERK     | 7788 | 1983-01-12 | 1100 | NULL |     20
  7900 | JAMES  | CLERK     | 7698 | 1981-12-03 |  950 | NULL |     30
  7902 | FORD   | ANALYST   | 7566 | 1981-12-03 | 3000 | NULL |     20
  7934 | MILLER | CLERK     | 7782 | 1982-01-23 | 1300 | NULL |     10

Time: 0.657 ms
scott@[local]:5432 scottdb#SQL> \t
Tuples only is off.
scott@[local]:5432 scottdb#SQL> select * from emp;     -- 헤더 출력
 empno | ename  |    job    | mgr  |  hiredate  | sal  | comm | deptno 
-------+--------+-----------+------+------------+------+------+--------
  7369 | SMITH  | CLERK     | 7902 | 1980-12-17 |  800 | NULL |     20
  7499 | ALLEN  | SALESMAN  | 7698 | 1981-02-20 | 1600 |  300 |     30
  7521 | WARD   | SALESMAN  | 7698 | 1981-02-22 | 1250 |  500 |     30
  7566 | JONES  | MANAGER   | 7839 | 1981-04-02 | 2975 | NULL |     20
  7654 | MARTIN | SALESMAN  | 7698 | 1981-09-28 | 1250 | 1400 |     30
  7698 | BLAKE  | MANAGER   | 7839 | 1981-05-01 | 2850 | NULL |     30
  7782 | CLARK  | MANAGER   | 7839 | 1981-06-09 | 2450 | NULL |     10
  7788 | SCOTT  | ANALYST   | 7566 | 1982-12-09 | 3000 | NULL |     20
  7839 | KING   | PRESIDENT | NULL | 1981-11-17 | 5000 | NULL |     10
  7844 | TURNER | SALESMAN  | 7698 | 1981-09-08 | 1500 |    0 |     30
  7876 | ADAMS  | CLERK     | 7788 | 1983-01-12 | 1100 | NULL |     20
  7900 | JAMES  | CLERK     | 7698 | 1981-12-03 |  950 | NULL |     30
  7902 | FORD   | ANALYST   | 7566 | 1981-12-03 | 3000 | NULL |     20
  7934 | MILLER | CLERK     | 7782 | 1982-01-23 | 1300 | NULL |     10
(14 rows)

Time: 0.682 ms
scott@[local]:5432 scottdb#SQL> \q      -- 종료
[postgres@olmaster:~]$ 

   

postgresdba.com