Function to get surrounding lines from a text.
You can choose how many surrounding lines to show using the second to last adjacent_line_count argument.
-- With `adjacent_line_count = 1`
SELECT utils.get_surrounding_lines('Hey\nthere\nhow\nare\nyou', 3, 1, 1) AS snippet1;
-- With `adjacent_line_count = 2`
SELECT utils.get_surrounding_lines('Hey\nthere\nhow\nare\nyou', 3, 2, 1) AS snippet2;| snippet1 |
|---|
| 2 there 3 -->how 4 are |
| snippet2 |
|---|
| 1 Hey 2 there 3 -->how 4 are 5 you |
You can highlight the line number with last argument as 1.
SELECT utils.get_surrounding_lines('Hey\nthere\nhow\nare\nyou', 3, 1, 1) AS snippet;| snippet |
|---|
| 2 there 3 -->how 4 are |
You can avoid highlighting the line number with last argument as 0.
SELECT utils.get_surrounding_lines('Hey\nthere\nhow\nare\nyou', 3, 1, 0) AS snippet;| snippet |
|---|
| 2 there 3 how 4 are |