#28857: Cast function may generate invalid SQL on PostgreSQL for complex
expressions
-------------------------------------+-------------------------------------
     Reporter:  Jurica Železnjak     |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  1.11
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  postgres,orm         |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Jurica Železnjak):

 Replying to [comment:3 Tim Graham]:
 > 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.

 True, but that's not the point. The point is that with the default
 implementation of Cast function it would work fine always, but with the
 overridden postgresql-specific it does not.
 ObjectAtPath does its own thing like it should - fetches a value by key
 from JSON field.

 {{{
     def as_postgresql(self, compiler, connection):
         # CAST would be valid too, but the :: shortcut syntax is more
 readable.
         return self.as_sql(compiler, connection,
 template='%(expressions)s::%(db_type)s')
 }}}

 But the reasoning for the built-in shortcut postgresql-specific method is
 that it would be more readable - while that's true - it leads to the
 mentioned problem.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28857#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.cf623cfe16099a0d1a48855931ab71d4%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to