Last active
January 10, 2018 14:41
-
-
Save rianby64/b91fb02efbfaab68492cf4dbf2388855 to your computer and use it in GitHub Desktop.
TCL SQL notify listen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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