| 88 | |
| 89 | @unittest.skipUnless(connection.vendor == "postgresql", "PostgreSQL specific tests") |
| 90 | def test_explicit_cast(self): |
| 91 | qs = Author.objects.annotate( |
| 92 | json_array=JSONArray(Cast("age", CharField())) |
| 93 | ).values("json_array") |
| 94 | with self.assertNumQueries(1) as ctx: |
| 95 | self.assertSequenceEqual(qs, [{"json_array": ["30"]}]) |
| 96 | sql = ctx.captured_queries[0]["sql"] |
| 97 | self.assertIn("::varchar", sql) |
| 98 | self.assertNotIn("::varchar)::varchar", sql) |
| 99 | |
| 100 | def test_order_by_key(self): |
| 101 | qs = Author.objects.annotate(arr=JSONArray(F("alias"))).order_by("arr__0") |