Changes between Initial Version and Version 3 of Ticket #28857
- Timestamp:
- Nov 29, 2017, 8:05:14 AM (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #28857
- Property Summary PostgreSQL Cast function shortcut → Cast 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. 1 In some cases when using the shortcut notation "::", the database gives an error. 3 2 4 GOOD: 5 CAST("sensors_sensordata"."data" #>> '{Temperature}' AS DOUBLE PRECISION) AS "temp" 3 GOOD: `CAST("sensors_sensordata"."data" #>> '{Temperature}' AS DOUBLE PRECISION) AS "temp"` 6 4 7 ERROR: 8 "sensors_sensordata"."data" #>> '{Temperature}'::DOUBLE PRECISION AS "temp" 5 ERROR: `"sensors_sensordata"."data" #>> '{Temperature}'::DOUBLE PRECISION AS "temp"` 9 6 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: 7 I've got a response from PostgreSQL people and they've said: 13 8 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. 15 12 16 In other words, not a bug. 17 ------------ 18 19 So it seems the as_postgresql method needs to wrap the expression into parenthesis. 13 So it seems the `as_postgresql()` method needs to wrap the expression into parenthesis. 20 14 https://docs.djangoproject.com/en/1.11/_modules/django/db/models/functions/base/#Cast