BUG: views not adhering to sort order in view definition

Author: michi-zuriCreated Feb 21, 2023Updated Sep 28, 2026
Labelsbuggood first issueaccepted :+1:

Describe the bug A clear and concise description of what the bug is.

To Reproduce

  1. Run this sql:
sql
DROP VIEW IF EXISTS "public"."test_view";
DROP TABLE IF EXISTS "public"."test_table";

CREATE TABLE "public"."test_table" (
  "id" int,
  "val" int
);

INSERT INTO 
  "public"."test_table"
VALUES
  (1,5),
  (2,6),
  (3,4),
  (4,3),
  (5,7),
  (6,10),
  (7,8),
  (8,9),
  (9,1),
  (10,2);
   
CREATE
  VIEW "public"."test_view" AS
SELECT
  "id",
  "val"
FROM
  "test_table"
ORDER BY
  "val";
  
SELECT * FROM "public"."test_view";
  1. See correctly ordered output in the query output.
  2. Open the newly created view from the sidebar
  3. the view data wrongly ordered by the first column (id)

Expected behavior I would the output from running the query select * from view1 to be equivalent to opening the view from the sidebar and to respect the order specified in the view definition. The order rules in the view definition are an important part of the added value of the view compared to the original table(s).

Version Information

  • OS: Windows Installer and Windows Portable
  • App Version 3.8.9 Ultimate
  • Database type and version: Posgresql 14.7

Additional context The sort order is respected if I run the query select * from testing by itself, but not when I open the view by double clicking on it.

Source: beekeeper-studio/beekeeper-studio