Eleven
Eleven

Reputation: 339

postgres is ignoring "-" when sorting

Im sorting the values. Postgres is ignoring "-". Here's my query:

select 0 as key, 
       '------ select ------' as value 
union 
SELECT contact_replica_child.contact_id as key,
       contact_replica_child.last_name||', '||contact_replica_child.first_name as value 
FROM contact_replica_child 
  join listing_replica_child on contact_replica_child.administrative_agency_id = listing_replica_child.agency_id 
where listing_replica_child.session_id = '3edfa73687a53604a50708d3d5d90221' 
order by value ;

Im getting this:

  key   |          value          
--------+-------------------------
 581489 | Contact, Administrative
 581490 | Green, Kelley
      0 | ------ select ------

Im expecting this:

  key   |          value          
--------+-------------------------
      0 | ------ select ------
 581489 | Contact, Administrative
 581490 | Green, Kelley

Any solution?

Upvotes: 1

Views: 41

Answers (1)

Mureinik
Mureinik

Reputation: 311393

Although I must admit I don't understand why Postgres is acting this way, you can easily work around it by limiting the order by clause to the second query only, using parentheses:

SELECT    0 AS key, '------ select ------' AS value 
UNION ALL
(SELECT   contact_replica_child.contact_id AS key,
          contact_replica_child.last_name || ',' ||  contact_replica_child.first_name AS value 
 FROM     contact_replica_child 
 JOIN     listing_replica_child ON 
          contact_replica_child.administrative_agency_id = 
          listing_replica_child.agency_id
 WHERE    listing_replica_child.session_id = '3edfa73687a53604a50708d3d5d90221' 
 ORDER BY value
);

Upvotes: 1

Related Questions