skip to Main Content

I want to get the list of last n number of table names present in a schema in a particular database. The problem is there are lots of tables and is not convenient to scroll through all of them to reach the end. Is there a way I can use something equivalent of tail -f command which is used to look at the recent updates in a log file.

I have tried something like tail -f dt in the current schema. But doesn’t work.

3

Answers


  1. This is it:

    select * from (
    SELECT table_name,ROW_NUMBER () OVER (
           ORDER BY table_name desc
        ) as id FROM information_schema.tables
    ) where id<=5;
    

    for example you can replace 5 with any number.

    Login or Signup to reply.
  2. It should be with alias name in sub query

    select * from (
    SELECT table_name,ROW_NUMBER () OVER (
           ORDER BY table_name desc
        ) as id FROM information_schema.tables
    )x where id<=5;
    
    Login or Signup to reply.
  3. In unix terminal. You can do following.
    ending 5 rows. 7 = 5+ row(table rows count) + 1(empty new line).

    /usr/local/pgsql15/bin/psql test15 -c 'dt' | tail -7
    

    print first 5 row.You can

    /usr/local/pgsql15/bin/psql test15 -c 'dt' | head -8
    

    8 = 5 + following 3 meta row.

    • row("List of relations")
    • row( Schema | Name | Type | Owner)
    • row(--------+-------------------------+-------------------+-------)
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search