Opened 7 years ago
Last modified 7 years ago
#28857 closed Bug
PostgreSQL Cast function shortcut — at Initial Version
Reported by: | Jurica Železnjak | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.11 |
Severity: | Normal | Keywords: | postgres, orm |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
In some cases when using the shortcut notation "::" the database gives an
error.
GOOD:
CAST("sensors_sensordata"."data" #>> '{Temperature}' AS DOUBLE PRECISION) AS "temp"
ERROR:
"sensors_sensordata"."data" #>> '{Temperature}'::DOUBLE PRECISION AS "temp"
I've got a response from Postgre people and they've said:
The precedence between the two is different. The equivalent would be:
("sensors_sensordata"."data" #>> '{Temperature}')::DOUBLE PRECISION
In other words, not a bug.
So it seems the as_postgresql method needs to wrap the expression into parenthesis.
https://docs.djangoproject.com/en/1.11/_modules/django/db/models/functions/base/#Cast