Sunday, September 13, 2009

Important Meta Commands in PostgreSQL

\c database name [username]
  • to connect to a database
\l
  • will return you the list of available databases
\du
  • will return you the list of databases users
\dt
  • will return you the list of tables in connected database
\d table name
  • will returns you the structure of the given table
\e
  • opens the sql query in editor or opens an editor to write query
show port
  • will returns you the port no on which postgres is running

few notations which are supposed to use while parsing these inputs :
  • -d : database name
  • -U : User name
  • -h : Host name
  • -p : Port No.
  • -f : File name (sql)
  • -w : Password

Wednesday, September 9, 2009

Working with Duplicate Rows in SQL

Duplicate Rows :
  • The default display of queries is all rows, including duplicate rows
  • postgres=# select deptno from emp;
    deptno
    --------
    20
    30
    30
    20
    30
    30
    10
    20
    10
    30
    20
    30
    20
    10
    (14 rows)
Selecting Unique Rows (Deleting Duplicates) :
  • postgres=# select distinct deptno from emp;
deptno
--------
10
20
30
(3 rows)

Followers