query db from edge function returns error PGRST002
edge functions🔢DB Connections
On a brand new project with default settings, no Data API enabled I have created a few simple tables. I have created a simple test edge function with the following:
// Setup type definitions for built-in Supabase Runtime APIsimport "jsr:@supabase/functions-js/edge-runtime.d.ts";interface reqPayload { name: string;}import "jsr:@supabase/functions-js/edge-runtime.d.ts";// @ts-ignoreimport { createClient } from "npm:@supabase/[email protected]";const supabase = createClient( Deno.env.get("SUPABASE_URL")!, Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!,);console.info('server started');Deno.serve(async (req: Request) => { const { name }: reqPayload = await req.json(); const result = await supabase.from('pg_catalog.pg_tables').select('*'); const data = { message: `Hello ${name}!`, result: result }; return new Response( JSON.stringify(data), { headers: { 'Content-Type': 'application/json', 'Connection': 'keep-alive' }} );});
// Setup type definitions for built-in Supabase Runtime APIsimport "jsr:@supabase/functions-js/edge-runtime.d.ts";interface reqPayload { name: string;}import "jsr:@supabase/functions-js/edge-runtime.d.ts";// @ts-ignoreimport { createClient } from "npm:@supabase/[email protected]";const supabase = createClient( Deno.env.get("SUPABASE_URL")!, Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!,);console.info('server started');Deno.serve(async (req: Request) => { const { name }: reqPayload = await req.json(); const result = await supabase.from('pg_catalog.pg_tables').select('*'); const data = { message: `Hello ${name}!`, result: result }; return new Response( JSON.stringify(data), { headers: { 'Content-Type': 'application/json', 'Connection': 'keep-alive' }} );});
However the result is always the same:
{"message":"Hello Functions!","result":{"error":{"code":"PGRST002","details":null,"hint":null,"message":"Could not query the database for the schema cache. Retrying."},"data":null,"count":null,"status":503,"statusText":"Service Unavailable"}}
{"message":"Hello Functions!","result":{"error":{"code":"PGRST002","details":null,"hint":null,"message":"Could not query the database for the schema cache. Retrying."},"data":null,"count":null,"status":503,"statusText":"Service Unavailable"}}
What is error code PGRST002? Anyone know how to get this edge function working? Is there some permission issue not reported properly?
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.