“ORDER BY … USING” clause in PostgreSQL

后端 未结 4 418
别那么骄傲
别那么骄傲 2020-12-13 18:10

The ORDER BY clause is decribed in the PostgreSQLdocumentation as:

ORDER BY expression [ ASC | DESC | USING operator ] [ NULLS { FIRST | LAST } ] [, ...]
         


        
4条回答
  •  心在旅途
    2020-12-13 18:34

    Samples:

    CREATE TABLE test
    (
      id serial NOT NULL,
      "number" integer,
      CONSTRAINT test_pkey PRIMARY KEY (id)
    )
    
    insert into test("number") values (1),(2),(3),(0),(-1);
    
    select * from test order by number USING > //gives 3=>2=>1=>0=>-1
    
    select * from test order by number USING < //gives -1=>0=>1=>2=>3
    

    So, it is equivalent to desc and asc. But you may use your own operator, that's the essential feature of USING

提交回复
热议问题