Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

370
Views
Writing a function (UDF) in SQL to auto populate Group By Numbers

In Snowflake, you can write a UDF to automate many repetitive tasks. One of which I'd like to write a function to is to automatically populate Group By 1,2,3,4,5... columns. Frankly, I am curious why no modern databases do it, cause after all, it should be relatively easy to figure out which column in the result is a dimension and which is an aggregation.

The UDF can be written in Javascript or some other kind of languages.

Any thoughts or suggestions on how I can proceed with this idea?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Such functionality is supported by dbt macros. Using a macro from a package:

select
  field_1,
  field_2,
  field_3,
  field_4,
  field_5,
  count(*)
from my_table
{{ dbt_utils.group_by(5) }}

It requires to know how many non-aggregated column exist in advance. More at: group_by


I am curious why no modern databases do it, cause after all, it should be relatively easy to figure out which column in the result is a dimension and which is an aggregation.

The closest equivalent is GROUP BY ALL from DuckDB: Friendlier SQL with DuckDB

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!