coygeek
## Summary All three complete trigger-function examples in `examples/prompts/use-realtime.md` put `AS $$` immediately after `RETURNS TRIGGER`, then repeat `AS $$` after `LANGUAGE plpgsql`. The first pair of dollar delimiters quotes the function attributes rather than the `BEGIN ... END` body, and the final delimiter starts an unterminated dollar-quoted string. ## Steps to reproduce 1. Open the [Database Triggers examples](https://github.com/supabase/supabase/blob/4ab54b935919ba3f4bb92f436ae4e757108e4f8a/examples/prompts/use-realtime.md#L167-L237). 2. Copy any complete function statement, such as `notify_table_changes()`, into a disposable PostgreSQL SQL session. This report has not executed the SQL on PostgreSQL; the evidence is source inspection of the exact delimiters. 3. Inspect the reproduced function header and delimiter sequence. The first example begins and ends as follows: ```sql CREATE OR REPLACE FUNCTION notify_table_changes() RETURNS TRIGGER AS $$ 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; $$; ``` The same header and three `$$` delimiters occur in `room_messages_broadcast_trigger()` and `notify_custom_event()`. ## Expected behavior Each complete example is a valid `CREATE FUNCTION ... RETURNS trigger` statement with function attributes outside the quoted body, a balanced body delimiter pair, and valid PL/pgSQL syntax. ## Actual behavior Each statement has three occurrences of the same dollar-quote delimiter. `SECURITY DEFINER`, `LANGUAGE plpgsql`, and `AS` fall inside the first quoted string. `BEGIN ... END` falls outside it, and the last `$$` has no closing delimiter. The documented statement cannot form a valid function definition. ## Affected area `examples/prompts/use-realtime.md`, `notify_table_changes()`, `room_messages_broadcast_trigger()`, and `notify_custom_event()` at revision `4ab54b935919ba3f4bb92f436ae4e757108e4f8a`. ## Runtime or environment Source inspection at the repository's `master` head, revision `4ab54b935919ba3f4bb92f436ae4e757108e4f8a`. No PostgreSQL server or live Supabase project was used. This report does not assert an observed PostgreSQL error string or broadcast runtime behavior. ## Evidence - [notify_table_changes](https://github.com/supabase/supabase/blob/4ab54b935919ba3f4bb92f436ae4e757108e4f8a/examples/prompts/use-realtime.md#L173-L192). - [room_messages_broadcast_trigger](https://github.com/supabase/supabase/blob/4ab54b935919ba3f4bb92f436ae4e757108e4f8a/examples/prompts/use-realtime.md#L196-L215). - [notify_custom_event](https://github.com/supabase/supabase/blob/4ab54b935919ba3f4bb92f436ae4e757108e4f8a/examples/prompts/use-realtime.md#L221-L237). - [PostgreSQL CREATE FUNCTION syntax](https://www.postgresql.org/docs/current/sql-createfunction.html). ## Impact Users and coding agents cannot create the documented trigger functions by copying these examples into a migration or SQL editor. ## Additional context The closure check is that all three complete examples have balanced body delimiters and create valid PL/pgSQL trigger functions in a disposable database with the required Realtime functions available. This report concerns function-definition syntax only; it does not validate argument order, channel behavior, or authorization semantics.