From 9b73129c3e1158fb922927399095327b1807489d Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Mon, 4 Oct 2021 09:57:20 -0700 Subject: [PATCH] Specify ORDER BY enumsortorder for postgres enums Co-authored-by: Daniel Colson --- .../lib/active_record/connection_adapters/postgresql_adapter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index aa85667b5a..c7a1838985 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -459,7 +459,7 @@ module ActiveRecord query = <<~SQL SELECT type.typname AS name, - string_agg(enum.enumlabel, ',') AS value + string_agg(enum.enumlabel, ',' ORDER BY enum.enumsortorder) AS value FROM pg_enum AS enum JOIN pg_type AS type ON (type.oid = enum.enumtypid)