﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28857	Cast function may generate invalid SQL on PostgreSQL for complex expressions	Jurica Železnjak	SShayashi	"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 PostgreSQL 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"	Bug	closed	Database layer (models, ORM)	1.11	Normal	fixed	postgres,orm		Ready for checkin	1	0	0	0	1	0
