https://github.com/johto/plpgsql-topological-sort
Topological sort in plain PL/PgSQL (and hstore)
https://github.com/johto/plpgsql-topological-sort
hstore kahn kahns-algorithm pgsql plpgsql postgresql sort topological topological-sort
Last synced: 7 months ago
JSON representation
Topological sort in plain PL/PgSQL (and hstore)
- Host: GitHub
- URL: https://github.com/johto/plpgsql-topological-sort
- Owner: johto
- License: mit
- Created: 2017-07-19T20:27:40.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-23T23:51:15.000Z (about 8 years ago)
- Last Synced: 2025-01-09T06:15:14.890Z (9 months ago)
- Topics: hstore, kahn, kahns-algorithm, pgsql, plpgsql, postgresql, sort, topological, topological-sort
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
I needed a topological sort in PL/PgSQL, so here it is. This is probably not
especially fast, but it's written in pure PL/PgSQL using only hstore.Example usage with the graph on the Wikipedia page:
```SQL
SELECT topological_sort(
ARRAY[5,7,3,11,8,2,9,10],
hstore '11 => "{5,7}", 8 => "{7,3}", 2 => "{11}", 9 => "{8,11}", 10 => "{3,11}"'
);
```result:
```
topological_sort
---------------------
{5,7,3,11,8,2,10,9}
(1 row)
```