https://github.com/nowayhecodes/postgres-datastream-sample
A sample on how to perform data streaming through PostgreSQL
https://github.com/nowayhecodes/postgres-datastream-sample
Last synced: 11 months ago
JSON representation
A sample on how to perform data streaming through PostgreSQL
- Host: GitHub
- URL: https://github.com/nowayhecodes/postgres-datastream-sample
- Owner: nowayhecodes
- Created: 2023-08-05T21:22:47.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-05T21:52:24.000Z (almost 3 years ago)
- Last Synced: 2025-07-02T01:40:34.143Z (about 1 year ago)
- Language: Python
- Size: 46.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# postgres-datastream-sample
This repo shows a sample on how to perform data streaming with PostgreSQL.
Create a trigger function using the `pg_notify()` function.
Them create another trigger to call the first one everytime an insertion on the messages table occurs.
Using the PostgreSQL `LISTEN` function in the psql terminal we can get an output like this:

Then running the `listen.py` file:

And then, running the `main.py` file (which is a flask app) in another terminal, then calling `http://127.0.0.1/message/1` on Postman:

This way we can do SSE to our frontends, or other integrations with message queues and stuff.