File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments