Showing posts with label psql. Show all posts
Showing posts with label psql. Show all posts

[PostgreSQL] Take backup of the individual table in postgres

pg_dump -t <table-name> <database-name> > /tmp/file_name.dump
Continue Reading

PostgreSQL: Handling the sequence value in psql(Reset sequence/ Get sequence next value)

PostgreSQL: Reset the sequence value of the table

Example1

select setval('students_id_seq',1706);

Result

  setval
--------
   1706
(1 row)

===============================

Example2(Recommanded)

To reset the sequence exactly to the recent primarykey id. This is the best idea to reset the sequence by avoiding usual conflicts.

select setval('students_id_seq',(select max(id) from students)) 

Result

  setval
--------
   1706
(1 row)

 

===============================

PostgreSQL: Get the next sequence value of the table

select nextval('students_id_seq');

Result

 nextval
---------
    1707
(1 row)

Continue Reading