К основному контенту

Сообщения

Сообщения за январь, 2020

Исключение группы в регулярных выражениях (non-capturing group)

(?:from|join) [ \r\n\t]{0,}([a-z._]{0,}) ?: begin non-capturing group Выделенная группа не будет учитываться ... пример получения всех таблиц из накопленной статистики запросов with t1 as ( select queryid, calls, lower(query) as full_query, replace((regexp_matches(lower(query), '(?: from | join | lateral )[ \r\n\t]{0,}(["a-z0-9._]{0,})','gm'))[1],'"','') as foundedfulltable from pg_stat_statements where lower(query) not like '%function%' ) , t2 as ( select queryid, calls, regexp_replace(full_query, E'[\\n\\r\\t\\u2028]+', ' ', 'gm' ) as full_query, foundedfulltable ,case when strpos(foundedfulltable,'.')>0 then (regexp_match(foundedfulltable, '([a-z_]{1,})\.{1}(?:[a-z0-9_]{1,})'))[1] else null end as foundedschema ,case when strpos(foundedfulltable,'.')>0 then (regexp_match(foundedfulltable, '(?:[a-z_]{1,})\.{1}([a-z0-9_]{1,})'))[1] else foundedfulltab...

Получение типа колонки в запросе

with t1 as ( select 100::int2 as col1, 200::int4 as col2, 'c'::char as col3, 'text1'::varchar(100) as col4, 'text2'::text as col5 ) select col1, pg_typeof (col1), col2, pg_typeof (col2), col3, pg_typeof (col3), col4, pg_typeof (col4), col5, pg_typeof (col5) from t1