#26355: Postgres ArrayField append
----------------------------------+--------------------------------------
Reporter: graup | Owner:
Type: New feature | Status: new
Component: contrib.postgres | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by graup):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
> I am using an ArrayField to store a list of dates. I would like to use
> `update()` to add a value to the list, only if the list doesn't contain
> it already.
>
> The `contains` part is already supported by Django, but not the
> `array_append`.
>
> http://www.postgresql.org/docs/9.1/static/arrays.html#ARRAYS-MODIFYING
>
> Eventually I'd like to be able to do something like this:
>
> `User.objects.exclude(active_in__contains=[current_month]).update(active_in=F('active_in')
> + [current_month])`
>
> which should result in this SQL:
>
> `UPDATE user_user SET active_in = array_append(active_in, [%s]) WHERE
> NOT(active_in @> ARRAY[%s]::varchar[]) ['2012-01']`
>
> PS: I want to use `update` instead of `get()` and `save()` for
> performance reasons.
New description:
I am using an ArrayField to store a list of dates. I would like to use
`update()` to add a value to the list, only if the list doesn't contain it
already.
The `contains` part is already supported by Django, but not the
`array_append`.
http://www.postgresql.org/docs/9.1/static/arrays.html#ARRAYS-MODIFYING
Eventually I'd like to be able to do something like this:
`User.objects.exclude(active_in__contains=[current_month]).update(active_in=F('active_in')
+ [current_month])`
which should result in this SQL:
`UPDATE user_user SET active_in = array_append(active_in, [%s]) WHERE
NOT(active_in @> ARRAY[%s]::varchar[]) ['2012-01']`
PS: I want to use `update` instead of `get()` and `save()` for performance
reasons.
I want to add that in this particular use case I can get around using it
(because I already have the user object anyway), but it would nevertheless
be nice of have this feature, I think.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/26355#comment:1>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/063.7c76ede5e61bd21b426b48ac8c1fc34e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.