Thread: SEQUENCES
<div class="Section1"><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-US" style="font-size: 10.0pt;font-family:Arial"> Hi all,</span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-US" style="font-size: 10.0pt;font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-US" style="font-size: 10.0pt;font-family:Arial"> I need to get all sequences and their respective current values! Is there any catalog table orany other away to get this???</span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-US" style="font-size: 10.0pt;font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-US" style="font-size: 10.0pt;font-family:Arial"> Thanks in advance.</span></font></div>
On Mon, Oct 02, 2006 at 01:39:38PM -0300, Rodrigo Sakai wrote: > > I need to get all sequences and their respective current values! Is there > any catalog table or any other away to get this??? Here's a quick way to do it in a shell script, although it'd be sort of inefficient: for name in `psql -c "select relname from pg_class where relkind = 'S'" dbname; do psql -c "select last_value from $name" dbname; done. A -- Andrew Sullivan | ajs@crankycanuck.ca Unfortunately reformatting the Internet is a little more painful than reformatting your hard drive when it gets out of whack. --Scott Morris
Rodrigo Sakai wrote on 02.10.2006 18:39: > Hi all, > > > > I need to get all sequences and their respective current values! Is there > any catalog table or any other away to get this??? > > Quote from the manual at: http://www.postgresql.org/docs/8.1/static/catalog-pg-class.html "The catalog pg_class catalogs tables and most everything else that has columns or is otherwise similar to a table. This includes indexes (but see also pg_index), sequences, views, composite types" Thomas
On Mon, Oct 02, 2006 at 13:39:38 -0300, Rodrigo Sakai <rodrigo.sakai@zanthus.com.br> wrote: > Hi all, > > > > I need to get all sequences and their respective current values! Is there > any catalog table or any other away to get this??? You can get their names from pg_class (with relkind = 'S') and then iterate over the names and look at the table underlying each table (at last_value).