{"id":10618,"date":"2026-02-19T05:29:49","date_gmt":"2026-02-19T05:29:49","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=10618"},"modified":"2026-02-19T07:46:10","modified_gmt":"2026-02-19T07:46:10","slug":"get-row-number-postgresql","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/","title":{"rendered":"How to Get Row Number in PostgreSQL"},"content":{"rendered":"\n<p>Often PostgreSQL database administrators need to calculate row number in database tables for different purposes and applications. PostgreSQL provides row_number() partition function for this purpose. In this article, we will learn why we need to calculate row number in PostgreSQL, how to get row number in PostgreSQL and its features.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/#Why_to_Get_Row_Number_in_PostgreSQL\" >Why to Get Row Number in PostgreSQL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/#How_to_Get_Row_Number_in_PostgreSQL\" >How to Get Row Number in PostgreSQL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/#1_Basic_Usage_with_Order_By\" >1. Basic Usage with Order By<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/#2_Using_Partition\" >2. Using Partition<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/#3_Without_Using_ORDER_BY\" >3. Without Using ORDER BY<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/#Features_of_Row_Number_in_PostgreSQL\" >Features of Row Number in PostgreSQL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_to_Get_Row_Number_in_PostgreSQL\"><\/span>Why to Get Row Number in PostgreSQL<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>There are several common applications where you need to calculate row number in PostgreSQL database.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Ranking<\/strong> &#8211; You may need to rank table rows based on one or more criteria. In such cases, it is easy to assign row numbers to each row, based on those criteria, to rank them.<\/li>\n\n\n\n<li><strong>Pagination<\/strong> &#8211; When you need to display a large number of rows of information on a web page, then web developers tend to paginate the results. For this purpose, it is very useful to assign row numbers  to paginate them. Pagination is very useful while working with large datasets.<\/li>\n\n\n\n<li><strong>Duplicate Removal<\/strong> &#8211; It is also useful in assigning row numbers to identify <a href=\"https:\/\/ubiq.co\/tech-blog\/mysql-remove-duplicate-records\/\">duplicate rows<\/a> in a table. You can do this by numbering rows within a group and selecting rows where row_number>1.<\/li>\n\n\n\n<li><strong>Data Analysis &amp; Reporting<\/strong> &#8211; Row numbers are frequently required for <a href=\"https:\/\/ubiq.co\/business-intelligence-software-tools\">data analysis and reporting<\/a> system where you need to rank rows based on one or more criteria.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Get_Row_Number_in_PostgreSQL\"><\/span>How to Get Row Number in PostgreSQL<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Let us say you have the following <em>sales<\/em> table.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#- create table sales(id int, product varchar(255),orders int);<br><br>#- insert into sales(id,product,orders) values<br>        (1,'A',50),<br>        (2,'B',60),<br>        (3,'A',70),<br>        (4,'B',40),<br>        (5,'C',50),<br>        (1,'A',50),<br>        (4,'B',40);<br><br>#- select * from sales;<br>+------+---------+--------+<br>| id   | product | orders |<br>+------+---------+--------+<br>|    1 | A       |     50 |<br>|    2 | B       |     60 |<br>|    3 | A       |     70 |<br>|    4 | B       |     40 |<br>|    5 | C       |     50 |<br>|    1 | A       |     50 |<br>|    4 | B       |     40 |<br>+------+---------+--------+<\/pre>\n\n\n\n<p>There are 3 ways to assign row number to this table in PostgreSQL.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Basic_Usage_with_Order_By\"><\/span>1. Basic Usage with Order By<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this case, we mention ORDER BY clause within OVER() function. The ORDER BY clause ensures that the row numbers are consistent and predictable. This is one of the most common ways to get row number.<\/p>\n\n\n\n<p>Here is the query to implement this.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#- select id,product,orders,<br>   row_number() over (order by orders desc) as row_num<br>   from sales;<br><br>+------+---------+--------+---------+<br>| id   | product | orders | row_num |<br>+------+---------+--------+---------+<br>|    3 | A       |     70 |       1 |<br>|    2 | B       |     60 |       2 |<br>|    1 | A       |     50 |       3 |<br>|    5 | C       |     50 |       4 |<br>|    1 | A       |     50 |       5 |<br>|    4 | B       |     40 |       6 |<br>|    4 | B       |     40 |       7 |<br>+------+---------+--------+---------+<\/pre>\n\n\n\n<p>In this query, the entire table is considered as a single group of rows. Its rows are ordered by orders column. Then each row is sequentially numbered starting from 1. In case of a tie in <em>orders<\/em> column value, row number is sequentially assigned.<\/p>\n\n\n\n<p>This solution is useful if you want to sequentially number all rows in a table, without any partitioning.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_Partition\"><\/span>2. Using Partition<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can group the rows into different partitions so that the row number restarts from 1, for each partition. Here is an example to rank rows for each product.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#- select id,product,orders,row_number() <br>over (partition by product order by orders desc) as row_num<br>from sales;<br><br>+------+---------+--------+---------+<br>| id   | product | orders | row_num |<br>+------+---------+--------+---------+<br>|    3 | A       |     70 |       1 |<br>|    1 | A       |     50 |       2 |<br>|    1 | A       |     50 |       3 |<br>|    2 | B       |     60 |       1 |<br>|    4 | B       |     40 |       2 |<br>|    4 | B       |     40 |       3 |<br>|    5 | C       |     50 |       1 |<br>+------+---------+--------+---------+<\/pre>\n\n\n\n<p>In the above query, rows for each unique value of product column are considered as single group. For each group, the row number begins from 1 and increases sequentially.<\/p>\n\n\n\n<p>This solution is useful if you want to partition the table rows into different groups and assign unique row numbers for each group, starting from 1.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Without_Using_ORDER_BY\"><\/span>3. Without Using ORDER BY<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can also use row_number() function without using ORDER BY clause. In this case, each row will be assigned a unique row number but its order may not be predictable.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#- select id,product,orders,row_number() over () as row_num<br>from sales;<br><br>+------+---------+--------+---------+<br>| id   | product | orders | row_num |<br>+------+---------+--------+---------+<br>|    1 | A       |     50 |       1 |<br>|    2 | B       |     60 |       2 |<br>|    3 | A       |     70 |       3 |<br>|    4 | B       |     40 |       4 |<br>|    5 | C       |     50 |       5 |<br>|    1 | A       |     50 |       6 |<br>|    4 | B       |     40 |       7 |<br>+------+---------+--------+---------+<\/pre>\n\n\n\n<p>It is advisable to use ORDER BY clause to get stable and predictable row numbers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Features_of_Row_Number_in_PostgreSQL\"><\/span>Features of Row Number in PostgreSQL<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are some important features of row_number() function in PostgreSQL.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Sequential Numbering<\/strong> &#8211; It will assign a sequential and unique integer for each row starting from 1, and incrementing by 1 for each row. There are no gaps in the sequence. In case of ties, each row still gets a unique row number, whose order may or may not be defined using additional columns in order by clause.<\/li>\n\n\n\n<li><strong>Partitioning<\/strong> &#8211; It supports optional partitioning that splits the result into multiple partitions. For each partition the row number resets to 1.<\/li>\n\n\n\n<li><strong>Window Function<\/strong> &#8211; It assigns sequence number for a given set of rows related to present row. For each window, the numbering starts from 1.<\/li>\n\n\n\n<li><strong>Dynamic Numbering<\/strong> &#8211; These row numbers are calculated dynamically on the fly when you run the query, and not stored anywhere.<\/li>\n\n\n\n<li><strong>Sorting<\/strong> &#8211; You need to use ORDER BY clause within OVER() to correctly determine sequence of row numbers.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt why you need to get row number in PostgreSQL database. We have also learnt the different ways to calculate row number in PostgreSQL. Depending on your requirement, you can use any of these methods.<\/p>\n\n\n\n<p>Also read:<br><a href=\"https:\/\/ubiq.co\/tech-blog\/create-user-postgresql\/\">How to Create User in PostgreSQL<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-list-all-users-in-postgresql\/\">How to List All Users in PostgreSQL<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-alter-column-from-null-to-not-null\/\">How to Alter Column from Null to NOT Null<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you may need to get row number in PostgreSQL database. Here is how to calculate row number in PostgreSQL.<\/p>\n","protected":false},"author":1,"featured_media":10641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[348],"tags":[629],"class_list":["post-10618","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-postgresql","tag-row-number"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Get Row Number in PostgreSQL - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Sometimes you may need to get row number in PostgreSQL database. Here is how to calculate row number in PostgreSQL.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Get Row Number in PostgreSQL - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Sometimes you may need to get row number in PostgreSQL database. Here is how to calculate row number in PostgreSQL.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-19T05:29:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-19T07:46:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2026\/02\/get-row-number-postgresql.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"278\" \/>\n\t<meta property=\"og:image:height\" content=\"185\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/get-row-number-postgresql\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/get-row-number-postgresql\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Get Row Number in PostgreSQL\",\"datePublished\":\"2026-02-19T05:29:49+00:00\",\"dateModified\":\"2026-02-19T07:46:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/get-row-number-postgresql\\\/\"},\"wordCount\":718,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/get-row-number-postgresql\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2026\\\/02\\\/get-row-number-postgresql.jpg?fit=278%2C185&ssl=1\",\"keywords\":[\"row number\"],\"articleSection\":[\"PostgreSQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/get-row-number-postgresql\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/get-row-number-postgresql\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/get-row-number-postgresql\\\/\",\"name\":\"How to Get Row Number in PostgreSQL - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/get-row-number-postgresql\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/get-row-number-postgresql\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2026\\\/02\\\/get-row-number-postgresql.jpg?fit=278%2C185&ssl=1\",\"datePublished\":\"2026-02-19T05:29:49+00:00\",\"dateModified\":\"2026-02-19T07:46:10+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Sometimes you may need to get row number in PostgreSQL database. Here is how to calculate row number in PostgreSQL.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/get-row-number-postgresql\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/get-row-number-postgresql\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/get-row-number-postgresql\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2026\\\/02\\\/get-row-number-postgresql.jpg?fit=278%2C185&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2026\\\/02\\\/get-row-number-postgresql.jpg?fit=278%2C185&ssl=1\",\"width\":278,\"height\":185,\"caption\":\"get row number in postgresql\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/get-row-number-postgresql\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Get Row Number in PostgreSQL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sreeram-sreenivasan\\\/\"],\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/author\\\/wordpress\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Get Row Number in PostgreSQL - Ubiq BI","description":"Sometimes you may need to get row number in PostgreSQL database. Here is how to calculate row number in PostgreSQL.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/","og_locale":"en_US","og_type":"article","og_title":"How to Get Row Number in PostgreSQL - Ubiq BI","og_description":"Sometimes you may need to get row number in PostgreSQL database. Here is how to calculate row number in PostgreSQL.","og_url":"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2026-02-19T05:29:49+00:00","article_modified_time":"2026-02-19T07:46:10+00:00","og_image":[{"width":278,"height":185,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2026\/02\/get-row-number-postgresql.jpg","type":"image\/jpeg"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Get Row Number in PostgreSQL","datePublished":"2026-02-19T05:29:49+00:00","dateModified":"2026-02-19T07:46:10+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/"},"wordCount":718,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2026\/02\/get-row-number-postgresql.jpg?fit=278%2C185&ssl=1","keywords":["row number"],"articleSection":["PostgreSQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/","url":"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/","name":"How to Get Row Number in PostgreSQL - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2026\/02\/get-row-number-postgresql.jpg?fit=278%2C185&ssl=1","datePublished":"2026-02-19T05:29:49+00:00","dateModified":"2026-02-19T07:46:10+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Sometimes you may need to get row number in PostgreSQL database. Here is how to calculate row number in PostgreSQL.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2026\/02\/get-row-number-postgresql.jpg?fit=278%2C185&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2026\/02\/get-row-number-postgresql.jpg?fit=278%2C185&ssl=1","width":278,"height":185,"caption":"get row number in postgresql"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/get-row-number-postgresql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Get Row Number in PostgreSQL"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2026\/02\/get-row-number-postgresql.jpg?fit=278%2C185&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-2Lg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/10618","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=10618"}],"version-history":[{"count":25,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/10618\/revisions"}],"predecessor-version":[{"id":10646,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/10618\/revisions\/10646"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/10641"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=10618"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=10618"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=10618"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}