{{{
Coalesce(expression, Value('')) for expression in
c.get_source_expressions()
}}}
With a minor change it works as intended:
{{{
Coalesce(expression, Value('""')) for expression in
c.get_source_expressions()
}}}
Tested with Django 1.8.12 under Ubuntu with sqlite 3.8.2-1ubuntu2.1.
--
Ticket URL: <https://code.djangoproject.com/ticket/26468>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
When you say "not working for me" -- what did you give as inputs, what did
you expect to happen and what happened instead?
--
Ticket URL: <https://code.djangoproject.com/ticket/26468#comment:1>
Comment (by jerch):
I tried to concat to db fields into one output column like this:
{{{
expr = Concat(models.F('field1'), models.Value('"-"'), models.F('field2'),
outputfield=models.CharField())
}}}
Expected output: 'value_from_field_1-value_from_field_2'
Instead I just got an invalid syntax sql error.
--
Ticket URL: <https://code.djangoproject.com/ticket/26468#comment:2>
* keywords: => sqlite concat
* component: Uncategorized => Database layer (models, ORM)
--
Ticket URL: <https://code.djangoproject.com/ticket/26468#comment:3>
Comment (by jarshwah):
I can't reproduce:
{{{
In [6]: from django.db import connection
In [7]: connection.vendor
Out[7]: u'sqlite'
In [8]: concat = Concat(F('name'), Value('-'), F('motto'),
output_field=CharField())
In [9]: Company.objects.annotate(concat=concat).first().concat
Out[9]: u'HI-'
In [10]: concat = Concat(F('name'), Value('"-"'), F('motto'),
output_field=CharField())
In [11]: Company.objects.annotate(concat=concat).first().concat
Out[11]: u'HI"-"'
In [12]: import django
In [13]: django.get_version()
Out[13]: '1.10.dev20160401110429'
}}}
Note that I tried both Value('"-"') and Value('-'). You shouldn't be
injecting quotes into Value, it'll take care of itself.
Can you please post the full queryset you're running that generates the
error, and also print the underlying query of the queryset, like this:
{{{
qs = Model.objects.whatever()
print(qs.query)
}}}
Also, what version of Django are you using? Can you reproduce on master?
--
Ticket URL: <https://code.djangoproject.com/ticket/26468#comment:4>
* cc: josh.smeaton@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/26468#comment:5>
Comment (by jarshwah):
Can't reproduce on stable 1.8 or 1.9 either.
--
Ticket URL: <https://code.djangoproject.com/ticket/26468#comment:6>
* status: new => closed
* resolution: => needsinfo
Comment:
Please reopen if you can provide more details about your Django, Python
and SQLite3 version (`import sqlite3; sqlite3.version`).
--
Ticket URL: <https://code.djangoproject.com/ticket/26468#comment:7>