Skip to content

Conversation

forsaken628
Copy link
Collaborator

@forsaken628 forsaken628 commented Mar 12, 2025

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

Snowflake does not support this UNPIVOT AS syntax, but databricks does.

Example:

-- Create the unpivoted_monthly_sales table
CREATE TABLE unpivoted_monthly_sales(  empid INT,   jan INT,  feb INT,  mar INT,  apr INT);

-- Insert sales data
INSERT INTO unpivoted_monthly_sales VALUES
  (1, 10400,  8000, 11000, 18000),
  (2, 39500, 90700, 12000,  5300);

SELECT *
FROM unpivoted_monthly_sales
    UNPIVOT (amount
    FOR month IN (jan as 'Jan', feb AS 'F e b', mar 'MARCH', apr));
┌──────────────────────────────────────────────────────┐
│      empid      │       month      │      amount     │
│ Nullable(Int32) │ Nullable(String) │ Nullable(Int32) │
├─────────────────┼──────────────────┼─────────────────┤
│               1 │ Jan              │           10400 │
│               1 │ F e b            │            8000 │
│               1 │ MARCH            │           11000 │
│               1 │ apr              │           18000 │
│               2 │ Jan              │           39500 │
│               2 │ F e b            │           90700 │
│               2 │ MARCH            │           12000 │
│               2 │ apr              │            5300 │
└──────────────────────────────────────────────────────┘

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@github-actions github-actions bot added the pr-feature this PR introduces a new feature to the codebase label Mar 12, 2025
@forsaken628 forsaken628 requested a review from sundy-li March 13, 2025 06:11
@forsaken628 forsaken628 merged commit af3b69b into databendlabs:main Mar 13, 2025
79 checks passed
@forsaken628 forsaken628 deleted the unpivot branch March 13, 2025 09:09
@BohuTANG
Copy link
Member

Doc has updated: databendlabs/databend-docs@63f8b37

loloxwg pushed a commit to loloxwg/databend that referenced this pull request Apr 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: UNPIVOT supports AS
3 participants