0

I'm viewing a table in my command line but I'm not sure how it's sorted:

enter image description here

I use the TABLE "Notification"; command to display the rows in the table. Any tips on how to sort the display of this table? All my searches show how to sort a table result in a actual postgres query.

2
  • 2
    You have to run an actual PostgreSQL query with an ORDER BY clause. Commented May 16, 2022 at 16:46
  • 2
    Data in SQL tables is not ordered so you need specify an ORDER BY to sort by your desired field(s). TABLE is equivalent to SELECT * FROM some_table, so TABLE "Notification" ORDER BY some_fld. I would get into the habit of using SELECT. Commented May 16, 2022 at 18:16

1 Answer 1

1

To sort the rows by a certain order the ORDER BY is used.

For example (In your case):

SELECT id, watched FROM schema_name.notification ORDER BY id ASC;

This will sort the table by id ascending, but it can also be sorted decending by using DESC instead of ASC.

I hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.