regex_replace s funkci v replacementu

26 views
Skip to first unread message

Martin Janota

unread,
Jun 4, 2021, 3:00:10 AM6/4/21
to PostgreSQL-cz
Zdravím
existuje v postgresu nejaka funkce s podobnou funkcionalitou jako regex_replace s tim, ze by slo pouzit v nahrazeni funkci postgresu.

Priklad

regex_replace(s, '(\d+)', sqrt(\1))

pokud bych za s vložil 'Martin ma 25 jablek' vysledkem by bylo Martin ma 5 jablek.

Diky
Martin

Pavel Stehule

unread,
Jun 4, 2021, 3:10:58 AM6/4/21
to PostgreSQL-cz
Ahoj

pá 4. 6. 2021 v 9:00 odesílatel Martin Janota <janota...@gmail.com> napsal:
pokud vim, tak tohle v postgresu urcite neni. Z regexpu nelze evaluovat funkci. Mozna by neco mohl umet JsonPath - mozna regexpy v Perlu (resp. v PLPerlu). Ani to neni technicky mozne. regexp funkce v postgresu jsou obycejne funkce, a neni jim mozne predat AST nebo ukazatel na funkci.

Pavel




Diky
Martin

--
Tuto zprávu jste obdrželi, protože jste přihlášeni k odběru skupiny „PostgreSQL-cz“ ve Skupinách Google.
Chcete-li zrušit odběr skupiny a přestat dostávat e‑maily ze skupiny, zašlete e-mail na adresu postgresql-c...@googlegroups.com.
Chcete-li tuto diskusi zobrazit na webu, navštivte https://groups.google.com/d/msgid/postgresql-cz/CAD4%3DHgDDe2%2BM1A1-GjsVvg_VXwggn43iCzu65WidEDVfi4SgKg%40mail.gmail.com.

Jan Michálek

unread,
Jun 4, 2021, 3:27:37 AM6/4/21
to postgr...@googlegroups.com
Ale můžeš to prohnat přes gexec v psql.



pá 4. 6. 2021 v 9:10 odesílatel Pavel Stehule <pavel....@gmail.com> napsal:


--
Jelen
Starší čeledín datovýho chlíva

Pavel Stehule

unread,
Jun 4, 2021, 3:55:11 AM6/4/21
to PostgreSQL-cz


pá 4. 6. 2021 v 9:27 odesílatel Jan Michálek <godzil...@gmail.com> napsal:
Ale můžeš to prohnat přes gexec v psql.

jak to myslis?


Jan Michálek

unread,
Jun 4, 2021, 4:33:04 AM6/4/21
to postgr...@googlegroups.com
 SELECT regexp_replace('SELECT ''xxxx''', '''xxxx''',sqrt(4)::text) \gexec
Nějak takto.
Případně
SELECT regexp_replace('SELECT ''xxxx''', '''xxxx''', 'sqrt(4)') \gexec

pá 4. 6. 2021 v 9:55 odesílatel Pavel Stehule <pavel....@gmail.com> napsal:
Reply all
Reply to author
Forward
0 new messages