Refs #32858, Refs #32392 -- Restored using :: shortcut syntax in Cast() on PostgreSQL.

This partly reverts commit fdfbc66331
unnecessary since b69b0c3fe8.
This commit is contained in:
Mariusz Felisiak 2021-06-22 06:10:54 +02:00
parent b69b0c3fe8
commit e07609a0d1
3 changed files with 24 additions and 1 deletions

View file

@ -42,6 +42,12 @@ class Cast(Func):
template = "JSON_EXTRACT(%(expressions)s, '$')"
return self.as_sql(compiler, connection, template=template, **extra_context)
def as_postgresql(self, compiler, connection, **extra_context):
# CAST would be valid too, but the :: shortcut syntax is more readable.
# 'expressions' is wrapped in parentheses in case it's a complex
# expression.
return self.as_sql(compiler, connection, template='(%(expressions)s)::%(db_type)s', **extra_context)
def as_oracle(self, compiler, connection, **extra_context):
if self.output_field.get_internal_type() == 'JSONField':
# Oracle doesn't support explicit cast to JSON.