Skip to content

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

fix: add apostrophe for sql export (#37920)

hallidayo25af9fa6d352
diff --git a/apps/studio/components/interfaces/TableGridEditor/TableEntity.utils.ts b/apps/studio/components/interfaces/TableGridEditor/TableEntity.utils.ts
index 41afdff8602..7d208f3b351 100644
--- a/apps/studio/components/interfaces/TableGridEditor/TableEntity.utils.ts
+++ b/apps/studio/components/interfaces/TableGridEditor/TableEntity.utils.ts
@@ -39,12 +39,21 @@ export const formatTableRowsToSQL = (table: SupaTable, rows: any[]) => {
// We only check for NULL, array and JSON types, everything else we stringify
// given that Postgres can implicitly cast the right type based on the column type
+ // For string types, we need to deal with escaping single quotes
+ const stringFormats = ['text', 'varchar']
+
if (val === null) {
return 'null'
} else if (dataType === 'ARRAY') {
return `'${JSON.stringify(val).replace('[', '{').replace(/.$/, '}')}'`
} else if (format?.includes('json')) {
return `${JSON.stringify(val).replace(/\\"/g, '"').replace(/'/g, "''").replace('"', "'").replace(/.$/, "'")}`
+ } else if (
+ typeof format === 'string' &&
+ typeof val === 'string' &&
+ stringFormats.includes(format)
+ ) {
+ return `'${val.replaceAll("'", "''")}'`
} else {
return `'${val}'`
}
diff --git a/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx b/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx
index f835be98f68..84dff45cae3 100644
--- a/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx
+++ b/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx
@@ -210,11 +210,13 @@ const EntityListItem: ItemRenderer<Entity, EntityListItemProps> = ({
connectionString: project?.connectionString,
table: supaTable,
})
+
const formattedRows = rows.map((row) => {
- const formattedRow = row
- Object.keys(row).map((column) => {
- if (typeof row[column] === 'object' && row[column] !== null)
- formattedRow[column] = JSON.stringify(formattedRow[column])
+ const formattedRow = { ...row }
+ Object.keys(row).forEach((column) => {
+ if (typeof row[column] === 'object' && row[column] !== null) {
+ formattedRow[column] = JSON.stringify(row[column])
+ }
})
return formattedRow
})