Skip to content

Commit 56356ab

Browse files
committed
Document building simple comparison expressions
1 parent 8c1408f commit 56356ab

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

docs/source/conflict_handling.rst

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,28 @@ A row level lock is acquired before evaluating the condition and proceeding with
199199
200200
When writing expressions, refer to the data you're trying to upsert with ``EXCLUDED``. Refer to the existing row by prefixing the name of the table:
201201

202-
.. code-block:: python
202+
.. code-block:: python
203+
204+
RawSQL(MyModel._meta.db_table + '.mycolumn = EXCLUDED.mycolumn')
205+
206+
You can use :meth:`~django:django.db.models.expressions.CombinedExpression` to build simple comparion expressions:
203207

204-
RawSQL(MyModel._meta.db_table + '.mycolumn = EXCLUDED.mycolumn')
205208

209+
.. code-block:: python
210+
211+
from django.db.models import CombinedExpression, Col, Value
212+
213+
CombinedExpression(
214+
MyModel._meta.get_field('name').get_col(MyModel._meta.db_table)
215+
'=',
216+
Col('EXCLUDED', 'name'),
217+
)
218+
219+
CombinedExpression(
220+
MyModel._meta.get_field('active').get_col(MyModel._meta.db_table)
221+
'=',
222+
Value(True),
223+
)
206224
207225
208226
ConflictAction.NOTHING

0 commit comments

Comments
 (0)