The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
realtime: fix code example on trigger (#34485)
Filipe Cabaço5bdd8605fcc0
diff --git a/apps/docs/content/guides/realtime/subscribing-to-database-changes.mdx b/apps/docs/content/guides/realtime/subscribing-to-database-changes.mdxindex 138d27cc53c..d15ec3d4bbc 100644--- a/apps/docs/content/guides/realtime/subscribing-to-database-changes.mdx+++ b/apps/docs/content/guides/realtime/subscribing-to-database-changes.mdx@@ -34,19 +34,19 @@ Let's create a function that we can call any time a record is created, updated,{/* prettier-ignore */}```sql-create or replace function public.your_table_changes()-returns trigger+create or replace function public.your_table_changes()+returns triggerlanguage plpgsqlas $$beginperform realtime.broadcast_changes(- 'topic:' || NEW.id::text, -- topic - the topic to which we're broadcasting- TG_OP, -- event - the event that triggered the function- TG_OP, -- operation - the operation that triggered the function- TG_TABLE_NAME, -- table - the table that caused the trigger- TG_TABLE_SCHEMA, -- schema - the schema of the table that caused the trigger- NEW, -- new record - the record after the change- OLD -- old record - the record before the change+ 'topic:' || coalesce(NEW.topic, OLD.topic) ::text, -- topic - the topic to which we're broadcasting+ TG_OP, -- event - the event that triggered the function+ TG_OP, -- operation - the operation that triggered the function+ TG_TABLE_NAME, -- table - the table that caused the trigger+ TG_TABLE_SCHEMA, -- schema - the schema of the table that caused the trigger+ NEW, -- new record - the record after the change+ OLD -- old record - the record before the change);return null;end;@@ -60,7 +60,7 @@ Let's set up a trigger so the function is executed after any changes to the tabl{/* prettier-ignore */}```sqlcreate trigger handle_your_table_changes-after insert or update or delete+after insert or update or deleteon public.your_tablefor each rowexecute function your_table_changes ();