Hi,

Please find the attached patch to fix RM 2007: View Last 100 rows not
working with Pgadmin4.

To fix this issue I have changed the query which fetches the last 100 rows.

The issue is reproducible when we have more than one primary keys; because
the order by clause in the query was not applied on the individual primary
key.


Thanks,
Khushboo
diff --git a/web/pgadmin/tools/sqleditor/command.py b/web/pgadmin/tools/sqleditor/command.py
index edd412f..d79e25e 100644
--- a/web/pgadmin/tools/sqleditor/command.py
+++ b/web/pgadmin/tools/sqleditor/command.py
@@ -353,11 +353,11 @@ class TableCommand(GridCommand):
         if sql_filter is None:
             sql = render_template("/".join([self.sql_path, 'objectquery.sql']), object_name=self.object_name,
                                   nsp_name=self.nsp_name, pk_names=pk_names, cmd_type=self.cmd_type,
-                                  limit=self.limit)
+                                  limit=self.limit, primary_keys=primary_keys)
         else:
             sql = render_template("/".join([self.sql_path, 'objectquery.sql']), object_name=self.object_name,
                                   nsp_name=self.nsp_name, pk_names=pk_names, cmd_type=self.cmd_type,
-                                  sql_filter=sql_filter, limit=self.limit)
+                                  sql_filter=sql_filter, limit=self.limit, primary_keys=primary_keys)
 
         return sql
 
diff --git a/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/9.1_plus/objectquery.sql b/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/9.1_plus/objectquery.sql
index 8b96576..2c55e25 100644
--- a/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/9.1_plus/objectquery.sql
+++ b/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/9.1_plus/objectquery.sql
@@ -3,9 +3,9 @@ SELECT * FROM {{ conn|qtIdent(nsp_name, object_name) }}
 {% if sql_filter %}
 WHERE {{ sql_filter }}
 {% endif %}
-{% if pk_names %}
-ORDER BY {{ pk_names }}
-{% if cmd_type == 1 or cmd_type == 3 %}ASC {% elif cmd_type == 2 %}DESC {% endif %}
+{% if primary_keys %}
+ORDER BY {% for p in primary_keys %}{{p}}{% if cmd_type == 1 or cmd_type == 3 %} ASC{% elif cmd_type == 2 %} DESC{% endif %}
+{% if not loop.last %}, {% else %} {% endif %}{% endfor %}
 {% endif %}
 {% if limit > 0 %}
 LIMIT {{ limit }}
-- 
Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

Reply via email to