martes, 20 de octubre de 2009

Get list tables from postgres database

If we need to iterate over all tables of a certain schema, we can get the list of schema, table, type and user using psql:


$ psql -qAtF, -c "\dt da_schema.*"
da_schema,segments,table,jacen
da_schema,speeds,table,jacen
$ _


You can also use "*" in the schema name, for example:

$ psql -qAtF, -c "\dt da_schema*.*"
da_schema,segments,table,jacen
da_schema,speeds,table,jacen
da_schema_2,labels,table,jacen
da_schema_test,positions,table,jacen
$ _

2 comentarios:

  1. You could also write that as:

    psql -t -c "select relname from pg_stat_all_tables where schemaname='da_schema';"


    --Scott
    www.enterprisedb.com

    ResponderEliminar
  2. or shorter:

    psql -t -c "select tablename from pg_tables where schemaname='da_schema';"

    ResponderEliminar