#28805: Provide a new database function for RegexpReplace -------------------------------------+------------------------------------- Reporter: Joey Wilhelm | Owner: nobody Type: New feature | Status: new Component: Database layer | Version: master (models, ORM) | 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 -------------------------------------+-------------------------------------
Comment (by Joey Wilhelm): Yeah, I was debating the thought of creating some sort of `django- postgres-regex` package, for this and related functions. But if I could contribute it to core, why not, ya know? The implementation relatively easy; I based it off, I believe, Substr. {{{#!python from django.db.models import Func, Value class RegexpReplace(Func): function = 'REGEXP_REPLACE' def __init__(self, expression, pattern, replacement, **extra): if not hasattr(pattern, 'resolve_expression'): if not isinstance(pattern, str): raise TypeError("'pattern' must be a string") pattern = Value(pattern) if not hasattr(replacement, 'resolve_expression'): if not isinstance(replacement, str): raise TypeError("'replacement' must be a string") replacement = Value(replacement) expressions = [expression, pattern, replacement] super().__init__(*expressions, **extra) }}} -- Ticket URL: <https://code.djangoproject.com/ticket/28805#comment:3> 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 django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/069.a376fab4a68e84574be2491468c424be%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.