Skip to content

SSE

Also known as

sse_events_path, sse_path (with or without @ prefix)

Enable Server-Sent Events (SSE) streaming for the endpoint.

Syntax

@sse <path>
@sse <path> on <level>

level: info, notice, warning

Examples

Basic SSE Endpoint

sql
create function long_running_process(_id int)
returns void
language plpgsql
as $$
begin
  raise notice 'Starting process...';
  -- do work
  raise notice 'Progress: 50%%';
  -- more work
  raise notice 'Complete!';
end;
$$;

comment on function long_running_process(int) is
'HTTP POST
@sse /process/events';

With Notice Level

sql
comment on function background_task() is
'HTTP POST
@sse /task/updates on notice';

Warning Level Only

sql
comment on function critical_job() is
'HTTP POST
@sse /job/alerts on warning';

Behavior

  • Creates an SSE endpoint at the specified path
  • PostgreSQL RAISE statements become SSE events
  • Clients connect to SSE path to receive real-time updates
  • Use correlation headers to match SSE events to requests

Comments

Released under the MIT License.