Simplified Postgres table looks like this:
date attribute
2002-04-14 C
2001-12-07 A
1990-12-19 A
1990-12-20 B
1991-01-29 A
1991-07-01 C
1990-07-25 B
1999-05-13 B
1990-09-25 A
We need to add a boolean column checking whether the date is the most recent of entries of attribute. The desired_col in the table:
date attribute desired_col
2002-04-14 C TRUE
2001-12-07 A TRUE
1990-12-19 A FALSE
1990-12-20 B FALSE
1991-01-29 A FALSE
1991-07-01 C FALSE
1990-07-25 B FALSE
1999-05-13 B TRUE
1990-09-25 A FALSE
This is the closest thing I can find, but makes a new table, but I only want a column.
Someone knowledgeable has suggested creating a trigger, but I don't understand these or their relevance.
If it helps, we could do this in pandas with df['desired_col'] = (df.groupby('attribute')['date'].transform('max') == df['date']). How can we do this in PostgreSQL?