AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Malformed Dollar Quoting In Realtime Trigger Examples

Three trigger function examples in examples/prompts/use-realtime.md have incorrectly placed AS $$, resulting in invalid SQL that cannot be executed.

mediumConfidence 92%Supabase

Origin Analysis

The examples place AS $$ immediately after RETURNS TRIGGER, then repeat AS $$ after function attributes, causing the attributes to be inside the dollar-quoted string and leaving an unbalanced delimiter.
Open examples/prompts/use-realtime.md at lines 167-237. Copy any of the three complete CREATE FUNCTION statements into a PostgreSQL session. Observe that the statements fail due to incorrect dollar-quote placement, as the function attributes are included inside the first quoted string and the final $$ lacks a matching opening delimiter.

Fixing Code Block

CREATE OR REPLACE FUNCTION notify_table_changes() RETURNS TRIGGER SECURITY DEFINER LANGUAGE plpgsql AS $$ BEGIN PERFORM realtime.broadcast_changes( TG_TABLE_NAME ||':' || COALESCE(NEW.id, OLD.id)::text, TG_OP, TG_OP, TG_TABLE_NAME, TG_TABLE_SCHEMA, NEW, OLD ); RETURN COALESCE(NEW, OLD); END; $$; -- Apply the same header correction to room_messages_broadcast_trigger() -- and notify_custom_event(): move AS $$ from after RETURNS TRIGGER -- to before BEGIN, leaving SECURITY DEFINER and LANGUAGE plpgsql outside the body.
Removes the premature AS $$ immediately after RETURNS TRIGGER and places the single AS $$ delimiter directly before BEGIN. This keeps function attributes like SECURITY DEFINER and LANGUAGE plpgsql outside the dollar-quoted body and balances the delimiters.

Edge Case Audit

This is a documentation-only fix; no runtime or version compatibility risks. Rollback is straightforward by restoring the previous malformed examples. Ensure that any external references or copied snippets are updated consistently.

Ecosystem Topology