Skip to content
This repository was archived by the owner on Aug 4, 2023. It is now read-only.

Files

Latest commit

987671a · Dec 28, 2019

History

History
53 lines (35 loc) · 2.26 KB

get_surrounding_lines.md

File metadata and controls

53 lines (35 loc) · 2.26 KB

utils.get_surrounding_lines

Function to get surrounding lines from a text.

Usage of adjacent_line_count

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;

Output of adjacent_line_count

snippet1
2    there
3 -->how
4    are
snippet2
1    Hey
2    there
3 -->how
4    are
5    you

Usage with highlight

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;

Output with highlight

snippet
2     there
3 -->how
4    are

Usage without highlight

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;

Output without highlight

snippet
2     there
3     how
4     are