Browse Source

fix: regex formula corrections

pull/7019/head
Pranav C 1 year ago
parent
commit
b0d0d41bf3
  1. 2
      packages/nc-gui/utils/formulaUtils.ts
  2. 6
      packages/nocodb/src/db/functionMappings/pg.ts

2
packages/nc-gui/utils/formulaUtils.ts

@ -442,7 +442,7 @@ const formulas: Record<string, any> = {
}, },
REGEX_MATCH: { REGEX_MATCH: {
type: formulaTypes.NUMERIC, type: formulaTypes.STRING,
validation: { validation: {
args: { args: {
rqd: 2, rqd: 2,

6
packages/nocodb/src/db/functionMappings/pg.ts

@ -193,7 +193,7 @@ const pg = {
const source = (await fn(pt.arguments[0])).builder; const source = (await fn(pt.arguments[0])).builder;
const pattern = (await fn(pt.arguments[1])).builder; const pattern = (await fn(pt.arguments[1])).builder;
return { 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) => { REGEX_EXTRACT: async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
@ -201,7 +201,7 @@ const pg = {
const pattern = (await fn(pt.arguments[1])).builder; const pattern = (await fn(pt.arguments[1])).builder;
return { return {
builder: knex.raw( 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; const replacement = (await fn(pt.arguments[2])).builder;
return { return {
builder: knex.raw( builder: knex.raw(
`regexp_matches(${source}::text, ${pattern}::text, ${replacement}::text) ${colAlias}`, `REGEXP_REPLACE(${source}::text, ${pattern}::text, ${replacement}::text, 'g') ${colAlias}`,
), ),
}; };
}, },

Loading…
Cancel
Save