Skip to content

Tag: postgresql

Unique constraint keys not invoked when a field is NULL

I have a table named AQI, with the following column Only one unique value of date, pollutant_code, source_id and time are able to exist, so I defined a unique constraint source_code_time_uq. And the upsert query like The upsert method work normally when all the field available, but when I put NULL in the time…

Union of arrays as aggregate function

I have the following input: I want the following output: I am grouping by name. For each group, the count should be aggregated as the max and the options should be aggregated as the union. I am having troubles figuring out how do the the latter. Currently, I have this query: http://rextester.com/YTZ45626 I kn…