Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Declare Primary Key Ordering

James Taylor edited this page May 16, 2013 · 1 revision

As of Phoenix 1.2, you may now define your primary key columns as being ascending (ASC), the default, or descending (DESC). This is useful to ensure that the order your rows are returned in a SELECT statement matches your expectations. This can help performance, since it prevents having to explicitly sort them.

Here's an example of a table declared with a descending DATE column:

CREATE TABLE entity_archival(
    archival_date DATE NOT NULL,
    user_id CHAR(15) NOT NULL,
    entity_type CHAR(3) NOT NULL,
    entity_id CHAR(15) NOT NULL
    CONSTRAINT pk PRIMARY KEY (archival_date DESC, user_id, entity_type, entity_id))
Clone this wiki locally