HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

Is it possible in Firebird to create a single index with ascending and descending columns?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
createdescendingwithcolumnspossiblesingleandindexfirebirdascending

Problem

For instance, something equivalent to

CREATE INDEX Listing_Date_Idx ON ACTIVITY(Listing,Date_ DESC,Time_ DESC);

Solution

The syntax for index creation does not allow for this:

CREATE [UNIQUE] [ASC[ENDING] | [DESC[ENDING]] INDEX indexname
   ON tablename
   { ( [,  ...]) | COMPUTED BY (expression) }

  ::=  a column not of type ARRAY, BLOB or COMPUTED BY


As you must set a single order for the entire index, not for each individual column.

However,

It is quite valid to define both an ascending and a descending index
on the same column or key set.

Code Snippets

CREATE [UNIQUE] [ASC[ENDING] | [DESC[ENDING]] INDEX indexname
   ON tablename
   { (<col> [, <col> ...]) | COMPUTED BY (expression) }

<col>  ::=  a column not of type ARRAY, BLOB or COMPUTED BY

Context

StackExchange Database Administrators Q#193064, answer score: 6

Revisions (0)

No revisions yet.