Changes between Initial Version and Version 1 of Ticket #34858
- Timestamp:
- Sep 20, 2023, 2:39:55 PM (14 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #34858 – Description
initial v1 3 3 My model is defined like this: 4 4 5 ``` 5 {{{ 6 6 class Choice(models.Model): 7 7 choice_text = models.CharField(max_length=200) … … 9 9 arbitrary_num = models.PositiveIntegerField(default=1) 10 10 arbitrary_num2 = models.PositiveIntegerField(default=2) 11 ``` 11 }}} 12 12 13 13 And this query is failing with Oracle (Tested on 19.3), but not Postgres: 14 14 15 ``` 15 {{{ 16 16 s = Coalesce(F('arbitrary_num') + F('arbitrary_num2'), 17 17 Value(0, PositiveIntegerField())) … … 27 27 #qs = Choice.objects.annotate(s=s) 28 28 #list(qs) 29 30 ``` 29 }}} 31 30 32 31 The error (It's talking about the `Coalesce` function not having an `output_field`): 33 32 34 ``` 33 {{{ 35 34 django.core.exceptions.FieldError: Expression contains mixed types: IntegerField, PositiveIntegerField. You must set output_field. 36 ``` 35 }}} 37 36 38 37 I believe the error is correct, because I think adding two `PositiveIntegerField()` seem to result in an `IntegerField`, so we *need* to specify an `output_field` on `Coalesce` to tell Django the proper output type to use. My question is that this seem to only throw an error in Oracle, and *not* Postgres. So it seems like the behavior on Postgres is unexpected? Somehow, the `Case` statement swallows the exception in Postgres and generates correct result. This can be demonstrated by the queryset where the `Coalesce` function is annotated directly without a case statement -- in this case, both Postgres and Oracle fails with the above error.