Skip to content

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

Add client side validation for payload size in sql editor (#29173)

Joshen Limd1a9447a8599
diff --git a/apps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityTabResults.tsx b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityTabResults.tsx
index 22f615d3c2e..489c0e56110 100644
--- a/apps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityTabResults.tsx
+++ b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityTabResults.tsx
@@ -1,4 +1,4 @@
-import { Loader2 } from 'lucide-react'
+import { ExternalLink, Loader2 } from 'lucide-react'
import { useParams } from 'common'
import { subscriptionHasHipaaAddon } from 'components/interfaces/Billing/Subscription/Subscription.utils'
@@ -10,6 +10,7 @@ import { AiIconAnimation, Button } from 'ui'
import Results from './Results'
import { useSqlEditorV2StateSnapshot } from 'state/sql-editor-v2'
import { useFlag } from 'hooks/ui/useFlag'
+import Link from 'next/link'
export type UtilityTabResultsProps = {
id: string
@@ -58,6 +59,9 @@ const UtilityTabResults = ({
const readReplicaError =
state.selectedDatabaseId !== ref &&
result.error.message.includes('in a read-only transaction')
+ const payloadTooLargeError = result.error.message.includes(
+ 'Query is too large to be run via the SQL Editor'
+ )
return (
<div className="bg-table-header-light [[data-theme*=dark]_&]:bg-table-header-dark">
@@ -88,7 +92,7 @@ const UtilityTabResults = ({
</p>
</div>
) : (
- <div className="">
+ <div className="flex flex-col gap-y-1">
{formattedError.length > 0 ? (
formattedError.map((x: string, i: number) => (
<pre key={`error-${i}`} className="font-mono text-sm text-wrap">
@@ -96,7 +100,7 @@ const UtilityTabResults = ({
</pre>
))
) : (
- <p className="font-mono text-sm">Error: {result.error?.message}</p>
+ <p className="font-mono text-sm tracking-tight">Error: {result.error?.message}</p>
)}
{result.autoLimit && (
<p className="text-sm text-foreground-light">
@@ -110,6 +114,21 @@ const UtilityTabResults = ({
database instead.
</p>
)}
+ {payloadTooLargeError && (
+ <p className="text-sm text-foreground-light flex items-center gap-x-1">
+ Run this query by{' '}
+ <Link
+ target="_blank"
+ rel="noreferrer"
+ href={`/project/${ref}/settings/database`}
+ className="underline transition hover:text-foreground flex items-center gap-x-1"
+ >
+ connecting to your database directly
+ <ExternalLink size={12} />
+ </Link>
+ .
+ </p>
+ )}
</div>
)}
diff --git a/apps/studio/data/sql/execute-sql-query.ts b/apps/studio/data/sql/execute-sql-query.ts
index ad6798e5131..1ddb33adcc4 100644
--- a/apps/studio/data/sql/execute-sql-query.ts
+++ b/apps/studio/data/sql/execute-sql-query.ts
@@ -7,6 +7,7 @@ import {
} from 'lib/role-impersonation'
import type { ResponseError } from 'types'
import { sqlKeys } from './keys'
+import { MB } from 'lib/constants'
export type ExecuteSqlVariables = {
projectRef?: string
@@ -39,6 +40,12 @@ export async function executeSql(
): Promise<{ result: any }> {
if (!projectRef) throw new Error('projectRef is required')
+ const sqlSize = new Blob([sql]).size
+ // [Joshen] I think the limit is around 1MB from testing, but its not exactly 1MB it seems
+ if (sqlSize > 0.98 * MB) {
+ throw new Error('Query is too large to be run via the SQL Editor')
+ }
+
let headers = new Headers()
if (connectionString) headers.set('x-connection-encrypted', connectionString)