#34955: Make available the string concatenation operator `||` for PostgreSQL
-------------------------------------+-------------------------------------
Reporter: Paolo Melchiorre | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: field, database, | Triage Stage:
generated, output_field | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by David Sanders):
Throwing some fuel on the fire with a few fyi points
- Firstly just want to make it clear that pg marking concat() immutable
is a feature (by design) not a bug :D (it's "stable" but "immutable"
because settings can still affect the output)
- Apparently `||` is ANSI (TIL)
- Even though it is ANSI you still have to set mode `PIPES_AS_CONCAT` [1]
on MySQL
- `Concat()` doesn't actually use `Coalesce()` for pg because it doesn't
need it, NULLs are ignored with `CONCAT()` on pg [2]
- Unfortunately we can't change `Concat()` to use `||` because on pg it
_does_ evaluate NULLs. If it were to use `||` then we _would_ need to make
use of `Coalesce()` to make it consistent.
I'm kinda hoping though that we do get an immutable concat for pg because
concatenating strings seems to be a common desire, at least for me :D
Lastly can I just say that (somewhat jokingly but semi-serious)... we may
be missing the perfect opportunity to make use of the `__floordiv__()`
operator method [3] ;D
{{{
GeneratedField(expression=F('first_name') // F('last_name'))
}}}
[1] https://dev.mysql.com/doc/refman/8.0/en/sql-
mode.html#sqlmode_pipes_as_concat
[2] https://www.postgresql.org/docs/current/functions-string.html
[3] https://docs.python.org/3/reference/datamodel.html#emulating-numeric-
types
--
Ticket URL: <https://code.djangoproject.com/ticket/34955#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018baf7396e1-3de8cfff-1386-4b38-a396-510091082806-000000%40eu-central-1.amazonses.com.