Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Fix: convertArgumentTypes parsing bug (#27800)

Monica Khourycb9eff3c0cc6
diff --git a/apps/studio/components/interfaces/Database/Functions/Functions.utils.ts b/apps/studio/components/interfaces/Database/Functions/Functions.utils.ts
index 4735085221e..392cf12b978 100644
--- a/apps/studio/components/interfaces/Database/Functions/Functions.utils.ts
+++ b/apps/studio/components/interfaces/Database/Functions/Functions.utils.ts
@@ -5,21 +5,31 @@ import { isEmpty } from 'lodash'
* to args = {value: [{name:'a', type:'integer'}, {name:'b', type:'integer'}]}
*/
export function convertArgumentTypes(value: string) {
- const items = value?.split(',')
- if (isEmpty(value) || !items || items?.length == 0) return { value: [] }
+ const items = value?.split(',').map((item) => item.trim())
+ if (isEmpty(value) || !items || items.length === 0) return { value: [] }
+
const temp = items
.map((x) => {
- const str = x.trim()
- const splitted = str.split(' ')
- if (splitted.length === 2) {
- return { name: splitted[0], type: splitted[1] }
- }
- if (splitted.length === 1) {
- return { name: splitted[0], type: splitted[0] }
+ const regex = /(\w+)\s+([\w\[\]]+)(?:\s+DEFAULT\s+(.*))?/i
+ const match = x.match(regex)
+ if (match) {
+ const [, name, type, defaultValue] = match
+ let parsedDefaultValue = defaultValue ? defaultValue.trim() : undefined
+
+ if (
+ ['timestamp', 'time', 'timetz', 'timestamptz'].includes(type.toLowerCase()) &&
+ parsedDefaultValue
+ ) {
+ parsedDefaultValue = `'${parsedDefaultValue}'`
+ }
+
+ return { name, type, defaultValue: parsedDefaultValue }
+ } else {
+ console.error('Error while trying to parse function arguments', x)
+ return null
}
- console.error('Error while trying to parse function arguments', value)
})
- .filter(Boolean) as { name: string; type: string }[]
+ .filter(Boolean) as { name: string; type: string; defaultValue?: string }[]
return { value: temp }
}