MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / Example_extractWindowFunctions

Function Example_extractWindowFunctions

pkg/gosqlx/example_test.go:679–695  ·  view source on GitHub ↗

Example_extractWindowFunctions demonstrates extracting window functions.

()

Source from the content-addressed store, hash-verified

677
678// Example_extractWindowFunctions demonstrates extracting window functions.
679func Example_extractWindowFunctions() {
680 sql := `SELECT
681 name,
682 salary,
683 ROW_NUMBER() OVER (PARTITION BY department ORDER BY salary DESC) as rank,
684 AVG(salary) OVER (PARTITION BY department) as dept_avg
685 FROM employees`
686
687 ast, err := gosqlx.Parse(sql)
688 if err != nil {
689 log.Fatal(err)
690 }
691
692 functions := gosqlx.ExtractFunctions(ast)
693 fmt.Printf("Window functions found: %d\n", len(functions))
694 // Output: Window functions found: 2
695}

Callers

nothing calls this directly

Calls 2

ParseFunction · 0.92
ExtractFunctionsFunction · 0.92

Tested by

no test coverage detected