Column |
Type | Collation |
Nullable | Default
------------------+------------------------+-----------+----------+------------------------------------
id | bigint | | not null |
nextval('person_id_seq'::regclass)
first_name | character varying(50) |
| not null |
last_name | character varying(50) |
| not null |
email | character varying(150) | | |
gender | character varying(50) |
| not null |
date_of_birth | date | | not null |
country_of_birth | character
varying(150) | | not null |
car_id | bigint | | |
Indexes:
"person_pkey" PRIMARY
KEY, btree (id)
"person_car_id_key"
UNIQUE CONSTRAINT, btree (car_id)
Foreign-key constraints:
"person_car_id_fkey"
FOREIGN KEY (car_id) REFERENCES car(id)
(END)
id | first_name | last_name |
email | gender |
date_of_birth | country_of_birth | car_id
----+------------+-----------+------------------+--------+---------------+------------------+--------
1 | Fernanda | Beardon
| hello1@gmail.com | Female | 1952-10-02 | india | 10
2 | Ashok | Beardon | hello2@gmail.com | Female |
1952-10-02 | india | 11
(2 rows)
firstdb=# SELECT nextval('person_id_seq'::regclass);
nextval
---------
9
(1 row)
firstdb=# SELECT * FROM person_id_seq;
last_value | log_cnt | is_called
------------+---------+-----------
9 | 24 | t
(1 row)
firstdb=#
firstdb=# select * from car;
id | make
| model |
price
----+------------+----------+----------
10 | honda | onda
| 12600.00
11 | Land Rover | Sterling |
87665.38
(2 rows)
firstdb=# insert into person (first_name, last_name, email, gender,
date_of_birth, country_of_birth,car_id) values ('Vicky', 'Priya',
'vpriya@biglobe.ne.jp', 'Female', '03/02/1989', 'Liberia',11);
ERROR: duplicate key value
violates unique constraint "person_car_id_key"
DETAIL: Key (car_id)=(11) already
exists.
firstdb=# insert into car (id,make,model,price)
firstdb-# values
firstdb-# (16,'Honda','i 10',60000);
INSERT 0 1
firstdb=# insert into person (first_name, last_name, email, gender,
date_of_birth, country_of_birth,car_id) values ('Vicky', 'Priya',
'vpriya@biglobe.ne.jp', 'Female', '03/02/1989', 'Liberia',16);
INSERT 0 1
firstdb=#
ALTER sequence person_id_seq RESTART WITH 10;
firstdb=# ALTER sequence
person_id_seq RESTART WITH 10;
ALTER SEQUENCE
firstdb=#
firstdb=# SELECT * FROM person_id_seq;
last_value | log_cnt | is_called
------------+---------+-----------
10 | 0 | f
(1 row)
firstdb=#
firstdb=# insert into person (first_name, last_name, email, gender,
date_of_birth, country_of_birth) values ('Revathy', 'Ashok', 'reva@gmail.com',
'Female', '10/10/1989', 'Oman');
INSERT 0 1
firstdb=#
select * from person where first_name='Revathy';
firstdb=#
sequence id taken as 10.
id | first_name | last_name | email
| gender | date_of_birth | country_of_birth | car_id
----+------------+-----------+----------------+--------+---------------+------------------+--------
10 | Revathy | Ashok
| reva@gmail.com | Female | 1989-10-10
| Oman |
(1 row)
firstdb=# insert into person (first_name, last_name, email, gender,
date_of_birth, country_of_birth) values ('Poornima', 'Ashok',
'poorna@biglobe.ne.jp', 'Female', '03/02/1989', 'Liberia');
INSERT 0 1
firstdb=# id | first_name | last_name | email | gender | date_of_birth |
country_of_birth | car_id
----+------------+-------id | first_name | last_name | email | gender | date_of_birth |
country_of_birth | car_id
----+------------+-----------+----------------------+--------+---------------+------------------+--------
11 | Poornima | Ashok
| poorna@biglobe.ne.jp | Female | 1989-03-02 | Liberia |
(1
row)----+----------------------+--------+---------------+------------------+--------
11 | Poornima | Ashok
| poorna@biglobe.ne.jp | Female | 1989-03-02 | Liberia |
(1 row)
id | first_name | last_name |
email | gender |
date_of_birth | country_of_birth | car_id
----+------------+-----------+----------------------+--------+---------------+------------------+--------
11 | Poornima | Ashok
| poorna@biglobe.ne.jp | Female | 1989-03-02 | Liberia |
(1 row)
EXTENSION#
Postgresql is designed to be easily extensible. For this reason,extension
loaded into the database can function just like features that are built in.
SELECT * FROM
pg_available_extenstions;
name | default_version | installed_version
|
comment
--------------------+-----------------+-------------------+----------------------------------------------------------------------
pgrowlocks | 1.2 | | show row-level locking
information
moddatetime | 1.0 | | functions for tracking last
modification time
earthdistance | 1.1 | | calculate great-circle
distances on the surface of the Earth
intagg | 1.1 | | integer aggregator and
enumerator (obsolete)
btree_gin | 1.3 | | support for indexing
common datatypes in GIN
ltree | 1.1 | | data type for hierarchical
tree-like structures
tcn | 1.0 | | Triggered change notifications
dict_int | 1.0 | | text search dictionary
template for integers
dict_xsyn | 1.0 | | text search dictionary
template for extended synonym processing
btree_gist | 1.5 | | support for indexing
common datatypes in GiST
pageinspect | 1.7 | | inspect the contents
UNDERSTANDING UUID datatype:
Universally Unique Identifiers (UUID)