POSTGRESQL connect db, list database, show tables, select, update, delete, begin ve commit komutları aşağıdaki gibi kullanılmaktadır.

virtualm:~$ su – postgres

postgres@virtualm:~$ psql

postgres=# \l

List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-------------+----------+----------+------------+------------+-----------------------
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)

postgres=# create database testdb;

postgres=# \c testdb

testdb=# begin;

testdb=# CREATE TABLE tb_dgunler (
id integer UNIQUE,
gun integer NOT NULL,
ay varchar (50) NOT NULL,
yil integer NOT NULL,
dinigun text
);

testdb=# \d

List of relations
Schema | Name | Type | Owner | Size | Description
--------+------------+-------+----------+------------+-------------
public | tb_dgunler | table | postgres | 8192 bytes |
(1 row)

testdb=# \d tb_dgunler

Table "public.tb_dgunler"
Column | Type | Collation | Nullable | Default
---------+-----------------------+-----------+----------+---------
id | integer | | |
gun | integer | | not null |
ay | character varying(50) | | not null |
yil | integer | | not null |
dinigun | text | | |
Indexes:
"tb_dgunler_id_key" UNIQUE CONSTRAINT, btree (id)

testdb=# select * from tb_dgunler ;

id | gun | ay | yil | dinigun
----+-----+----+-----+---------
(0 rows)

testdb=# insert INTO public.tb_dgunler (id,gun,ay,yil,dinigun) values (1,29,’Mart’,2017,’3 Aylarn Balangc’);

testdb=# insert INTO public.tb_dgunler (id,gun,ay,yil,dinigun) values (2,30,’Mart’,2017,’Regaip Kandili’);

testdb=# insert INTO public.tb_dgunler (id,gun,ay,yil,dinigun) values (3,23,’Nisan’,2017,’Berat Kandili’);

testdb=# insert INTO tb_dgunler (id,gun,ay,yil) values (5,25,’Haziran’,2017);

testdb=# select * from tb_dgunler ;

id | gun | ay | yil | dinigun
----+-----+---------+------+------------------
1 | 29 | Mart | 2017 | 3 Aylarn Balangc
2 | 30 | Mart | 2017 | Regaip Kandili
3 | 23 | Nisan | 2017 | Berat Kandili
5 | 25 | Haziran | 2017 |
(4 rows)

testdb=# update tb_dgunler set dinigun = ‘Ramazan Bayrami’ where id = 5;
testdb=# select * from tb_dgunler ;

id | gun | ay | yil | dinigun
----+-----+---------+------+------------------
1 | 29 | Mart | 2017 | 3 Aylarn Balangc
2 | 30 | Mart | 2017 | Regaip Kandili
3 | 23 | Nisan | 2017 | Berat Kandili
5 | 25 | Haziran | 2017 | Ramazan Bayrami
(4 rows)

testdb=# update tb_dgunler SET gun =’12’ where id=1;
testdb=# select * from tb_dgunler;

id | gun | ay | yil | dinigun
----+-----+---------+------+------------------
3 | 23 | Nisan | 2017 | Berat Kandili
5 | 25 | Haziran | 2017 | Ramazan Bayrami
2 | 40 | Ocak | 2017 | Regaip Kandili
1 | 12 | Ocak | 2017 | 3 Aylarn Balangc
(4 rows)

testdb=# update tb_dgunler SET gun =’7′ where id=2;
testdb=# select * from tb_dgunler;

id | gun | ay | yil | dinigun
----+-----+---------+------+------------------
3 | 23 | Nisan | 2017 | Berat Kandili
5 | 25 | Haziran | 2017 | Ramazan Bayrami
1 | 12 | Ocak | 2017 | 3 Aylarn Balangc
2 | 7 | Ocak | 2017 | Regaip Kandili
(4 rows)

testdb=# update tb_dgunler SET ay=’Mart’ WHERE gun=12;
testdb=# select * from tb_dgunler;

id | gun | ay | yil | dinigun
----+-----+---------+------+------------------
3 | 23 | Nisan | 2017 | Berat Kandili
5 | 25 | Haziran | 2017 | Ramazan Bayrami
2 | 7 | Ocak | 2017 | Regaip Kandili
1 | 12 | Mart | 2017 | 3 Aylarn Balangc
(4 rows)

testdb=# delete from tb_dgunler where ay= ‘Haziran’;
testdb=# select * from tb_dgunler;

id | gun | ay | yil | dinigun
----+-----+-------+------+------------------
3 | 23 | Nisan | 2017 | Berat Kandili
2 | 7 | Ocak | 2017 | Regaip Kandili
1 | 12 | Mart | 2017 | 3 Aylarn Balangc
(3 rows)

testdb=# commit;

testdb=# \q

Kolay Gelsin…