Skip to content

Commit e5b676a

Browse files
committed
document that DurationField arithmetic doesn't work with dates
refs googleapis#253
1 parent 3264f75 commit e5b676a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,22 @@ Spanner has some limitations on schema changes which you must respect:
150150
* A table's primary key can't be altered.
151151
* Migrations aren't atomic since django-spanner doesn't support transactions.
152152

153+
### `DurationField` arithmetic doesn't work with `DateField` values
154+
155+
Spanner requires using different functions for arithmetic depending on the
156+
column type:
157+
158+
* `TIMESTAMP` columns (`DateTimeField`) require `TIMESTAMP_ADD` or
159+
`TIMESTAMP_SUB`
160+
* `DATE` columns (`DateField`) require `DATE_ADD` or `DATE_SUB`
161+
162+
Django doesn't provide a way to determine which database function to use.
163+
`DatabaseOperations.combine_duration_expression()` arbitrary uses
164+
`TIMESTAMP_ADD` and `TIMESTAMP_SUB`. Therefore, if you use a `DateField` in a
165+
`DurationField` expression, you'll see an error like: "No matching signature
166+
for function TIMESTAMP_SUB for argument types: DATE, INTERVAL INT64
167+
DATE_TIME_PART."
168+
153169
### Computations that yield FLOAT64 values can't be assigned to INT64 columns
154170

155171
Spanner [doesn't support this](https://github.com/googleapis/python-spanner-django/issues/331).

0 commit comments

Comments
 (0)