PostgreSQL basic command

Now I will try to explain about basic command from PostgreSQL. If we use MySQL, probably already familiar with command “use database, show tables, show databases, describe table”. And what about PostgreSQL?
So to know basic command such as above, see this:

Mysql PostgreSQL
SHOW tables; \d
SHOW databases; \l
DESC table; \d+ table or \d table


Example preview PostgreSQL \l:

postgres-# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
—————–+———-+———-+————-+————-+———————–
pembayaransiswa | imron | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
spp | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(5 rows)

postgres-#

Example preview PostgreSQL \d:

spp=> \d
List of relations
Schema | Name | Type | Owner
——–+——————+———-+——-
public | admin | table | imron
public | sequence | sequence | imron
public | siswa | table | imron
public | spp | table | imron
public | transaksi | view | imron
public | transaksi_spp | table | imron
public | user_id_sequence | sequence | imron
public | users | table | imron
(8 rows)

spp=>

And then for \d table:

spp=> \d siswa;
Table “public.siswa”
Column | Type | Modifiers
————+———————–+———–
no_induk | integer | not null
nama_siswa | character varying(50) |
kelas | character varying(4) |
Indexes:
“pk_siswa” PRIMARY KEY, btree (no_induk)
Referenced by:
TABLE “spp” CONSTRAINT “fk_spp_siswa” FOREIGN KEY (no_induk) REFERENCES siswa(no_induk)

spp=>

Source: http://www.linuxscrew.com

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s