I am transforming a db from postgres to mysql.

Since i have cannot look for a tool that does the secret itself, i am likely to convert all postgres sequences to autoincrement ids in mysql with autoincrement value.

So, how do i list all sequences inside a Postgres DB (8.1 version) with details about the table by which it's used, the following value etc having a SQL query?

Remember that i can not make use of the information_schema.sequences view within the 8.4 release.

The next query gives names of sequences.

SELECT c.relname FROM pg_class c WHERE c.relkind = 'S';

Typically a sequence is known as as ${table}_id_seq. Simple regex pattern matching provides you with the table title.

To obtain last worth of a sequence make use of the following query:

SELECT last_value FROM test_id_seq;

Run: psql -E, after which \ds

after some discomfort, i first got it.

the easiest method to accomplish this would be to list all tables

select * from pg_tables where schemaname = '<schema_name>'

after which, for every table, list all posts with characteristics

select * from information_schema.columns where table_name = '<table_name>'

then, for every column, test if it features a sequence

select pg_get_serial_sequence('<table_name>', '<column_name>')

after which, obtain the details about this sequence

select * from <sequence_name>

Partly examined but looks mostly complete.

select *
  from (select n.nspname,c.relname,
               (select substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)
                  from pg_catalog.pg_attrdef d
                 where d.adrelid=a.attrelid
                   and d.adnum=a.attnum
                   and a.atthasdef) as def
          from pg_class c, pg_attribute a, pg_namespace n
         where c.relkind='r'
           and c.oid=a.attrelid
           and n.oid=c.relnamespace
           and a.atthasdef
           and a.atttypid=20) x
 where x.def ~ '^nextval'
 order by nspname,relname;

Credit where credit arrives... it's partially reverse designed in the SQL drenched from the d on the known table which had a sequence. I am sure it may be cleaner too, but hey, performance wasn't an issue.