Changes between Initial Version and Version 1 of Ticket #36407, comment 4


Ignore:
Timestamp:
May 22, 2025, 1:55:22 PM (4 months ago)
Author:
ontowhee

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #36407, comment 4

    initial v1  
    22
    33With postgres, `ORDER BY 0` is erroring out because the `0` is referencing a [https://www.postgresql.org/docs/current/sql-select.html#SQL-ORDERBY:~:text=order%20by%202 column position] in the select list, and the column positions uses 1-indexing.
     4
     5----
    46
    57Interestingly, Oracle does not sort as expected when casting. The sql it generates using the test provided by Sarah is,
     
    810}}}
    911
    10 Also, I'm not sure how it is sorting with `ORDER BY 0` if a number is referencing the [https://oracle-base.com/articles/misc/sql-for-beginners-the-order-by-clause#:~:text=column%20position column position]. I wonder if it uses a default column that is different from the default column in Django.
     12Without casting, the query is,
     13
     14{{{
     15SELECT "ORDERING_ARTICLE"."ID", "ORDERING_ARTICLE"."AUTHOR_ID", "ORDERING_ARTICLE"."SECOND_AUTHOR_ID", "ORDERING_ARTICLE"."HEADLINE", "ORDERING_ARTICLE"."PUB_DATE" FROM "ORDERING_ARTICLE" ORDER BY 0 DESC
     16}}}
     17
     18I'm not sure how it is sorting with `ORDER BY 0` if a number is referencing the [https://oracle-base.com/articles/misc/sql-for-beginners-the-order-by-clause#:~:text=column%20position column position]. I wonder if it uses a default column that is different from the default column in Django. Running a small SQL [https://sqlfiddle.com/oracle/online-compiler?&id=f43e92f2-df6f-4b4a-a6b3-7ae436bd9bc6 example] directly on the database gives an error as expected
     19
     20{{{
     21SELECT id, first_name, dob FROM person ORDER BY 0
     22                                                *
     23ERROR at line 1:
     24ORA-01785: ORDER BY item must be the number of a SELECT-list expression
     25}}}
     26
     27but it raising an error in Django.
Back to Top