I am using Netezza (based on PostgreSQL) and need to select all columns in a table for rows distinct on one column. A related question with answer can be found here, but it doesn't handle the case with all columns, going by that answer throws an error:
select distinct on (some_field) table1.* from table1 order by some_field;
Snippet from error with real data:
"(" (at char 77) expecting '')''
I don't think your code should throw an error in Postgres. However, it won't do what you expect without an
order by
:The syntax of your query is correct for Postgres (like you declared at first). See:
You later clarified you actually work with Netezza, which is only loosely related to Postgres. Wikipedia states:
Netezza does not seem to support
DISTINCT ON ()
, onlyDISTINCT
.It supports
row_number()
, though. So this should work:The question remains: Which row do you want from each set with identical
some_field
. If any row is good, you are done here. Else, you need to addORDER BY
to theOVER
clause.Related: