Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

removeNullUnicode when JSON_EXTRACT

Fendy Heryantoe780a59bb368
diff --git a/packages/nocodb/src/db/functionMappings/pg.ts b/packages/nocodb/src/db/functionMappings/pg.ts
index 01f93fe340..6d213cb50f 100644
--- a/packages/nocodb/src/db/functionMappings/pg.ts
+++ b/packages/nocodb/src/db/functionMappings/pg.ts
@@ -416,9 +416,20 @@ END`,
JSON_EXTRACT: async ({ fn, knex, pt }: MapFnArgs) => {
const source = (await fn(pt.arguments[0])).builder;
const needle = (await fn(pt.arguments[1])).builder;
+
+ const removeNullUnicode = (source: string) => {
+ // use four backspace so it will translate into two backspace in sql query
+ return `regexp_replace(${source}, '\\\\u0000', 'u0000')`;
+ };
return {
builder: knex.raw(
- `CASE WHEN (?)::jsonb IS NOT NULL THEN jsonb_path_query_first((?)::jsonb, CONCAT('$', ?)::jsonpath) ELSE NULL END`,
+ [
+ `CASE WHEN ( ${removeNullUnicode('?')} )::jsonb IS NOT NULL`,
+ `THEN jsonb_path_query_first(( ${removeNullUnicode(
+ '?',
+ )} )::jsonb, CONCAT('$', ?)::jsonpath)`,
+ `ELSE NULL END`,
+ ].join(' '),
[source, source, needle],
),
};