surfacepipelinemelt
Pipelinepipeline · returns table

MELT

Transform columns to rows (unpivot/wide-to-long)

Table-in, table-out — composes downstream of SELECTs.

pipelinellmpipeline-composabletext

Syntax

THEN MELT {{ prompt }}
THEN MELT({{ prompt }})

Arguments

nametypedescription
promptVARCHAR
_tableTABLE

About

PIPELINE cascade for melting (unpivoting) wide data to long format. MELT is the inverse of PIVOT - it transforms columns into rows. Also known as UNPIVOT, GATHER, or WIDE-TO-LONG transformation. Uses structural caching via table_sql_execute mode: - LLM only sees table SCHEMA (column names + types), not actual data - Generates native DuckDB UNPIVOT SQL - SQL cached by schema fingerprint + prompt - Same table shape + same prompt = instant cache hit Usage examples: SELECT * FROM wide_sales THEN MELT 'convert quarterly columns to rows' SELECT * FROM data THEN MELT('q1_sales, q2_sales, q3_sales, q4_sales') SELECT * FROM data THEN MELT('revenue columns into period and amount') Example transformation: Input (wide): | product | q1_sales | q2_sales | q3_sales | | Widget | 100 | 150 | 200 | Output (long): | product | quarter | sales | | Widget | q1_sales | 100 | | Widget | q2_sales | 150 | | Widget | q3_sales | 200 |

Examples

Unpivots quarterly measure columns into long-form rows

SELECT
  *
FROM
  (
    VALUES
      ('Widget', 100, 150),
      ('Gadget', 80, 120)
  ) AS t (product, q1_sales, q2_sales) THEN MELT (
    'convert quarterly sales columns into quarter and sales'
  ) THEN PYTHON ('result = pd.DataFrame({"row_count":[len(df)]})')

Nearby rabbit holes

same domain
Climb back to The Looking Glass