Amazon Redshift 1.0.22169
I'm trying to order by company names and place any "N/A" values first. I have a simple test table like so:
+----+-----------+
| id | name |
+----+-----------+
| 1 | Company 3 |
| 2 | Company 1 |
| 3 | N/A |
| 4 | Company 2 |
+----+-----------+
With MySQL I use the following:
SELECT
`name` AS 'company'
FROM
`companies`
GROUP BY
`company`
ORDER BY
CASE `company` WHEN 'N/A' THEN 1 ELSE 2 END ASC,
`company` ASC
to get the desired result:
+-----------+
| company |
+-----------+
| N/A |
| Company 1 |
| Company 2 |
| Company 3 |
+-----------+
But when trying to do so in Redshift:
SELECT
"name" AS "company"
FROM
"companies"
GROUP BY
"company"
ORDER BY
CASE "company" WHEN 'N/A' THEN 1 ELSE 2 END ASC,
"company" ASC
I'm getting the following error:
Query 1 ERROR: ERROR: column "company" does not exist in companies
Any suggestions how this can be adjusted to work for PostgreSQL?