> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# STACK

> Splits row-major values into a fixed number of generated rows.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Table function</span></div>

NULL values remain NULL; missing cells in the final row are padded with NULL.

## Syntax

### Table

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
STACK(rows, value1 [, value2 ...])
```

## Arguments

| Name | Type | Required | Description |
| - | - | - | - |
| rows | positive INTEGER literal | Yes | Number of rows generated per input row. Must be a positive integer literal. Must be a constant argument. |
| value1 | BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY, MAP or STRUCT | Yes | First row-major value. For DECIMAL(p, s), p is precision (total digits) and s is scale (digits after the decimal point). |
| remaining\_values | BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY, MAP or STRUCT | No | Further values in row-major order. Values occupying the same output column must have the same type after conversion. For DECIMAL(p, s), p is precision (total digits) and s is scale (digits after the decimal point). This argument can repeat. |

## Returns

* Type: TABLE with ceil(number of values / rows) columns
* NULL behavior: NULL values remain NULL; missing cells in the final row are padded with NULL.
* Empty input: At least one value is required; unused cells in the final generated row are NULL.
* Shape: rows generated rows per input row; column count is ceil(number of supplied values / rows).
* Ordering: Values are placed row-major; SQL row order requires ORDER BY.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | No |
| Exact result | Yes |

## Usage notes

* INTEGER and INT mean the same type; STRING means VARCHAR text. NULL can be used with a supported type. Cast NULL explicitly when its type would otherwise be unclear.
* Deterministic: The same inputs and settings produce the same result.

## Examples

### Typical behavior

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT a, b FROM TABLE(stack(2, 1, 'x', 2)) AS t(a, b) ORDER BY a;
```

| a | b |
| - | - |
| 1 | x |
| 2 | NULL |

### Arrange values into rows

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT label, amount FROM TABLE(stack(2, 'a', 10, 'b', 20)) AS t(label, amount) ORDER BY label;
```

| label | amount |
| - | - |
| a | 10 |
| b | 20 |

## Limitations

* Values in the same output column must have the same type after conversion.
* rows must be a positive literal; at least one value is required.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.