By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
| version |
|---|
| PostgreSQL 14.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-4), 64-bit |
9 rows affected
| a | time | b | c |
|---|---|---|---|
| DT9834 | 2022-03-03 10:00:00 | 2 | 3 |
| LK0601 | 2022-03-03 10:00:00 | 1 | 3 |
| LM3526 | 2022-03-03 10:00:00 | 3 | 3 |
| QUERY PLAN |
|---|
| Sort (cost=66.17..66.18 rows=3 width=74) |
| Sort Key: table_first.a |
| -> HashAggregate (cost=66.12..66.15 rows=3 width=74) |
| Group Key: table_first.a, table_first.created_at, table_first.b, table_first.c |
| -> Append (cost=22.01..66.09 rows=3 width=74) |
| -> Limit (cost=22.01..22.02 rows=1 width=74) |
| -> Sort (cost=22.01..22.02 rows=1 width=74) |
| Sort Key: table_first.created_at DESC |
| -> Seq Scan on table_first (cost=0.00..22.00 rows=1 width=74) |
| Filter: ((created_at >= '2022-02-13 00:00:00'::timestamp without time zone) AND ((a)::text = 'LK0601'::text)) |
| -> Limit (cost=22.01..22.02 rows=1 width=74) |
| -> Sort (cost=22.01..22.02 rows=1 width=74) |
| Sort Key: table_first_1.created_at DESC |
| -> Seq Scan on table_first table_first_1 (cost=0.00..22.00 rows=1 width=74) |
| Filter: ((created_at >= '2022-02-13 00:00:00'::timestamp without time zone) AND ((a)::text = 'DT9834'::text)) |
| -> Limit (cost=22.01..22.02 rows=1 width=74) |
| -> Sort (cost=22.01..22.02 rows=1 width=74) |
| Sort Key: table_first_2.created_at DESC |
| -> Seq Scan on table_first table_first_2 (cost=0.00..22.00 rows=1 width=74) |
| Filter: ((created_at >= '2022-02-13 00:00:00'::timestamp without time zone) AND ((a)::text = 'LM3526'::text)) |
| QUERY PLAN |
|---|
| Unique (cost=23.04..23.06 rows=4 width=74) |
| -> Sort (cost=23.04..23.05 rows=4 width=74) |
| Sort Key: a, created_at DESC |
| -> Seq Scan on table_first (cost=0.00..23.00 rows=4 width=74) |
| Filter: ((created_at >= '2022-02-13 00:00:00'::timestamp without time zone) AND ((a)::text = ANY ('{LK0601,DT9834,LM3526}'::text[]))) |