From the course: PostgreSQL: Advanced Queries

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Output row numbers with query results

Output row numbers with query results - PostgreSQL Tutorial

From the course: PostgreSQL: Advanced Queries

Output row numbers with query results

- [Instructor] When you execute a query, depending on the graphical interface you're working with, you'll typically have a list of numbers down the left side of the results that indicate each rows number. For instance, if I select all of the product data, when I execute the query here in PGAdmin, the left of the data output grid shows each row's position in the results. These numbers aren't part of the actual data. They're just shown as a convenience here in the graphical interface. However, PostgreSQL does have a row number as function that'll add this kind of sequence number as a column in the result set, which makes it convenient if you want to export the data to a spreadsheet or incorporate it into a report. To add a column of row numbers, first, select your table columns as usual, then we'll create a column using the row number function. This is a window function, so it needs an over clause. That creates an…

Contents