Changes between Initial Version and Version 3 of Ticket #28857


Ignore:
Timestamp:
Nov 29, 2017, 8:05:14 AM (7 years ago)
Author:
Tim Graham
Comment:

It looks like parentheses could also be added to ObjectAtPath.template. Can you reproduce the problem with any of the built-in database functions? With either solution, it seems like unnecessary parenthesis would be present in some cases. It would be nice to avoid that if possible.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #28857

    • Property Summary PostgreSQL Cast function shortcutCast function may generate invalid SQL on PostgreSQL for complex expressions
  • Ticket #28857 – Description

    initial v3  
    1 In some cases when using the shortcut notation "::" the database gives an
    2 error.
     1In some cases when using the shortcut notation "::", the database gives an error.
    32
    4 GOOD:
    5   CAST("sensors_sensordata"."data" #>> '{Temperature}' AS DOUBLE PRECISION) AS "temp"
     3GOOD: `CAST("sensors_sensordata"."data" #>> '{Temperature}' AS DOUBLE PRECISION) AS "temp"`
    64
    7 ERROR:
    8   "sensors_sensordata"."data" #>> '{Temperature}'::DOUBLE PRECISION AS "temp"
     5ERROR: `"sensors_sensordata"."data" #>> '{Temperature}'::DOUBLE PRECISION AS "temp"`
    96
    10 I've got a response from Postgre people and they've said:
    11 --------------
    12 The precedence between the two is different.  The equivalent would be:
     7I've got a response from PostgreSQL people and they've said:
    138
    14   ("sensors_sensordata"."data" #>> '{Temperature}')::DOUBLE PRECISION
     9 The precedence between the two is different.  The equivalent would be:
     10 `("sensors_sensordata"."data" #>> '{Temperature}')::DOUBLE PRECISION`
     11 In other words, not a bug.
    1512
    16 In other words, not a bug.
    17 ------------
    18 
    19 So it seems the as_postgresql method needs to wrap the expression into parenthesis.
     13So it seems the `as_postgresql()` method needs to wrap the expression into parenthesis.
    2014https://docs.djangoproject.com/en/1.11/_modules/django/db/models/functions/base/#Cast
Back to Top