From: | Mitar <mmitar(at)gmail(dot)com> |
---|---|
To: | PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Allowing DESC for a PRIMARY KEY column |
Date: | 2024-03-29 20:34:27 |
Message-ID: | CAKLmikNCFD44VjzRCRwuiVWDOE=T7zsOzygd5XakKNdRgLv-Aw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi!
I have the same problem as [1]. I have table something like:
CREATE TABLE values (
id int NOT NULL,
revision int NOT NULL,
data jsonb NOT NULL,
PRIMARY KEY (id, revision)
)
And I would like to be able to specify PRIMARY KEY (id, revision DESC)
because the most common query I am making is:
SELECT data FROM values WHERE id=123 ORDER BY revision DESC LIMIT 1
My understanding, based on [2], is that the primary key index cannot
help here, unless it is defined with DESC on revision. But this does
not seem to be possible. Would you entertain a patch adding this
feature? It seems pretty straightforward?
Mitar
[1] https://stackoverflow.com/questions/45597101/primary-key-with-asc-or-desc-ordering
[2] https://www.postgresql.org/docs/16/indexes-ordering.html
--
https://mitar.tnode.com/
https://twitter.com/mitar_m
https://noc.social/@mitar
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2024-03-29 20:41:22 | Re: Allowing DESC for a PRIMARY KEY column |
Previous Message | Tom Lane | 2024-03-29 20:17:16 | Re: Why is parula failing? |