Skip to content

Instantly share code, notes, and snippets.

@rianby64
Last active January 10, 2018 14:41
Show Gist options
  • Save rianby64/b91fb02efbfaab68492cf4dbf2388855 to your computer and use it in GitHub Desktop.
Save rianby64/b91fb02efbfaab68492cf4dbf2388855 to your computer and use it in GitHub Desktop.
TCL SQL notify listen
package require Pgtcl
proc notification { d } {
puts "notification from SQL: $d"
# Here I expect to see
# notification from SQL: this is a payload
}
set db [pg_connect -conninfo \
[list host=localhost user=test dbname=test password=test]]
pg_listen $db "virtual" notification
set query {
DO
$BODY$
BEGIN
RAISE NOTICE 'doing a notification';
NOTIFY virtual, 'this is a payload';
-- I suggest you to check also pg_notify
END;
$BODY$;
}
set result [pg_exec $db $query]
if {[pg_result $result -status] != "PGRES_COMMAND_OK"} {
puts "[pg_result $result -status] [pg_result $result -error]"
}
vwait forever
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment