From b0d0d41bf32186b6f7ace082d6c54d29a814e0ef Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 22 Nov 2023 07:17:55 +0000 Subject: [PATCH] fix: regex formula corrections --- packages/nc-gui/utils/formulaUtils.ts | 2 +- packages/nocodb/src/db/functionMappings/pg.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/nc-gui/utils/formulaUtils.ts b/packages/nc-gui/utils/formulaUtils.ts index 43a6990a31..890329bbca 100644 --- a/packages/nc-gui/utils/formulaUtils.ts +++ b/packages/nc-gui/utils/formulaUtils.ts @@ -442,7 +442,7 @@ const formulas: Record = { }, REGEX_MATCH: { - type: formulaTypes.NUMERIC, + type: formulaTypes.STRING, validation: { args: { rqd: 2, diff --git a/packages/nocodb/src/db/functionMappings/pg.ts b/packages/nocodb/src/db/functionMappings/pg.ts index 7679f86ecf..427454d13b 100644 --- a/packages/nocodb/src/db/functionMappings/pg.ts +++ b/packages/nocodb/src/db/functionMappings/pg.ts @@ -193,7 +193,7 @@ const pg = { const source = (await fn(pt.arguments[0])).builder; const pattern = (await fn(pt.arguments[1])).builder; return { - builder: knex.raw(`${source}::text ~ ${pattern}::text) ${colAlias}`), + builder: knex.raw(`(${source}::text ~ ${pattern}::text) ${colAlias}`), }; }, REGEX_EXTRACT: async ({ fn, knex, pt, colAlias }: MapFnArgs) => { @@ -201,7 +201,7 @@ const pg = { const pattern = (await fn(pt.arguments[1])).builder; return { builder: knex.raw( - `regexp_matches(${source}::text, ${pattern}::text) ${colAlias}`, + `REGEXP_MATCHES(${source}::text, ${pattern}::text) ${colAlias}`, ), }; }, @@ -211,7 +211,7 @@ const pg = { const replacement = (await fn(pt.arguments[2])).builder; return { builder: knex.raw( - `regexp_matches(${source}::text, ${pattern}::text, ${replacement}::text) ${colAlias}`, + `REGEXP_REPLACE(${source}::text, ${pattern}::text, ${replacement}::text, 'g') ${colAlias}`, ), }; },