@rivascva/dt-idl 1.1.138 → 1.1.140
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/go/psql/utils.go +11 -0
- package/package.json +1 -1
package/go/psql/utils.go
CHANGED
|
@@ -65,6 +65,17 @@ func GetSelectAllQueryWithLimitAndOrderBy(table string, limit uint, orderByColum
|
|
|
65
65
|
return builder.ToSql()
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
// GetSelectEveryNthRowQuery builds and returns the query and arguments to perform a select all query that returns every nth row.
|
|
69
|
+
// Provide a where map to specify which rows to select. A nil value will select all rows.
|
|
70
|
+
func GetSelectEveryNthRowQuery(table string, orderByColumn string, n int, where ...Where) (string, []any, error) {
|
|
71
|
+
subquery := sq.Select("*", fmt.Sprintf("row_number() OVER (ORDER BY %s) AS row_num", orderByColumn)).From(table)
|
|
72
|
+
for _, mp := range where {
|
|
73
|
+
subquery = subquery.Where(mp)
|
|
74
|
+
}
|
|
75
|
+
builder := sq.Select("*").FromSelect(subquery, "t").Where(fmt.Sprintf("row_num %% %d = 0", n))
|
|
76
|
+
return builder.ToSql()
|
|
77
|
+
}
|
|
78
|
+
|
|
68
79
|
// GetSelectColumnQuery builds and returns the query and arguments to perform a select column query on the given table.
|
|
69
80
|
// Provide a where map to specify which rows to select. A nil value will select all rows.
|
|
70
81
|
func GetSelectColumnQuery(table string, column string, where ...Where) (string, []any, error) {
|