|
| 1 | +# Table Functions |
| 2 | +Table functions are methods for constructing tables or streams from various data sources or formats. They allow you to read data from files, databases, or other sources directly into a Timeplus stream or table. |
| 3 | + |
| 4 | +### values |
| 5 | + |
| 6 | +The `values` table function allows you to create temporary storage which fills |
| 7 | +columns with values. It is useful for quick testing or generating sample data. |
| 8 | + |
| 9 | +The basic syntax of the `values` table function is: |
| 10 | + |
| 11 | +```sql |
| 12 | +VALUES([structure,] values...) |
| 13 | +``` |
| 14 | + |
| 15 | +It is commonly used as: |
| 16 | + |
| 17 | +```sql |
| 18 | +VALUES( |
| 19 | + ['column1_name Type1, column2_name Type2, ...'], |
| 20 | + (value1_row1, value2_row1, ...), |
| 21 | + (value1_row2, value2_row2, ...), |
| 22 | + ... |
| 23 | +) |
| 24 | +``` |
| 25 | + |
| 26 | +- `column1_name Type1, ...` (optional). string |
| 27 | + specifying the column names and types. If this argument is omitted columns will |
| 28 | + be named as `c1`, `c2`, etc. |
| 29 | +- `(value1_row1, value2_row1)`. tuples |
| 30 | + containing values of any type. |
| 31 | + |
| 32 | +:::note |
| 33 | +Comma separated tuples can be replaced by single values as well. In this case |
| 34 | +each value is taken to be a new row. |
| 35 | +::: |
| 36 | + |
| 37 | +Returns a temporary table containing the provided values. |
| 38 | + |
| 39 | +```sql title="Query" |
| 40 | +SELECT * |
| 41 | +FROM VALUES( |
| 42 | + 'person string, place string', |
| 43 | + ('Noah', 'Paris'), |
| 44 | + ('Emma', 'Tokyo'), |
| 45 | + ('Liam', 'Sydney'), |
| 46 | + ('Olivia', 'Berlin'), |
| 47 | + ('Ilya', 'London'), |
| 48 | + ('Sophia', 'London'), |
| 49 | + ('Jackson', 'Madrid'), |
| 50 | + ('Alexey', 'Amsterdam'), |
| 51 | + ('Mason', 'Venice'), |
| 52 | + ('Isabella', 'Prague') |
| 53 | +) |
| 54 | +``` |
| 55 | + |
| 56 | +```response title="Response" |
| 57 | + ┌─person───┬─place─────┐ |
| 58 | + 1. │ Noah │ Paris │ |
| 59 | + 2. │ Emma │ Tokyo │ |
| 60 | + 3. │ Liam │ Sydney │ |
| 61 | + 4. │ Olivia │ Berlin │ |
| 62 | + 5. │ Ilya │ London │ |
| 63 | + 6. │ Sophia │ London │ |
| 64 | + 7. │ Jackson │ Madrid │ |
| 65 | + 8. │ Alexey │ Amsterdam │ |
| 66 | + 9. │ Mason │ Venice │ |
| 67 | +10. │ Isabella │ Prague │ |
| 68 | + └──────────┴───────────┘ |
| 69 | +``` |
| 70 | + |
| 71 | +`VALUES` can also be used with single values rather than tuples. For example: |
| 72 | + |
| 73 | +```sql title="Query" |
| 74 | +SELECT * |
| 75 | +FROM VALUES( |
| 76 | + 'person string', |
| 77 | + 'Noah', |
| 78 | + 'Emma', |
| 79 | + 'Liam', |
| 80 | + 'Olivia', |
| 81 | + 'Ilya', |
| 82 | + 'Sophia', |
| 83 | + 'Jackson', |
| 84 | + 'Alexey', |
| 85 | + 'Mason', |
| 86 | + 'Isabella' |
| 87 | +) |
| 88 | +``` |
| 89 | + |
| 90 | +```response title="Response" |
| 91 | + ┌─person───┐ |
| 92 | + 1. │ Noah │ |
| 93 | + 2. │ Emma │ |
| 94 | + 3. │ Liam │ |
| 95 | + 4. │ Olivia │ |
| 96 | + 5. │ Ilya │ |
| 97 | + 6. │ Sophia │ |
| 98 | + 7. │ Jackson │ |
| 99 | + 8. │ Alexey │ |
| 100 | + 9. │ Mason │ |
| 101 | +10. │ Isabella │ |
| 102 | + └──────────┘ |
| 103 | +``` |
| 104 | + |
| 105 | +Or without providing a row specification (`'column1_name type1, column2_name type2, ...'` |
| 106 | +in the syntax), in which case the columns are automatically named. |
| 107 | + |
| 108 | +For example: |
| 109 | + |
| 110 | +```sql title="Query" |
| 111 | +-- tuples as values |
| 112 | +SELECT * |
| 113 | +FROM VALUES( |
| 114 | + ('Noah', 'Paris'), |
| 115 | + ('Emma', 'Tokyo'), |
| 116 | + ('Liam', 'Sydney'), |
| 117 | + ('Olivia', 'Berlin'), |
| 118 | + ('Ilya', 'London'), |
| 119 | + ('Sophia', 'London'), |
| 120 | + ('Jackson', 'Madrid'), |
| 121 | + ('Alexey', 'Amsterdam'), |
| 122 | + ('Mason', 'Venice'), |
| 123 | + ('Isabella', 'Prague') |
| 124 | +) |
| 125 | +``` |
| 126 | + |
| 127 | +```response title="Response" |
| 128 | + ┌─c1───────┬─c2────────┐ |
| 129 | + 1. │ Noah │ Paris │ |
| 130 | + 2. │ Emma │ Tokyo │ |
| 131 | + 3. │ Liam │ Sydney │ |
| 132 | + 4. │ Olivia │ Berlin │ |
| 133 | + 5. │ Ilya │ London │ |
| 134 | + 6. │ Sophia │ London │ |
| 135 | + 7. │ Jackson │ Madrid │ |
| 136 | + 8. │ Alexey │ Amsterdam │ |
| 137 | + 9. │ Mason │ Venice │ |
| 138 | +10. │ Isabella │ Prague │ |
| 139 | + └──────────┴───────────┘ |
| 140 | +``` |
| 141 | + |
| 142 | +```sql |
| 143 | +-- single values |
| 144 | +SELECT * |
| 145 | +FROM VALUES( |
| 146 | + 'Noah', |
| 147 | + 'Emma', |
| 148 | + 'Liam', |
| 149 | + 'Olivia', |
| 150 | + 'Ilya', |
| 151 | + 'Sophia', |
| 152 | + 'Jackson', |
| 153 | + 'Alexey', |
| 154 | + 'Mason', |
| 155 | + 'Isabella' |
| 156 | +) |
| 157 | +``` |
| 158 | + |
| 159 | +```response title="Response" |
| 160 | + ┌─c1───────┐ |
| 161 | + 1. │ Noah │ |
| 162 | + 2. │ Emma │ |
| 163 | + 3. │ Liam │ |
| 164 | + 4. │ Olivia │ |
| 165 | + 5. │ Ilya │ |
| 166 | + 6. │ Sophia │ |
| 167 | + 7. │ Jackson │ |
| 168 | + 8. │ Alexey │ |
| 169 | + 9. │ Mason │ |
| 170 | +10. │ Isabella │ |
| 171 | + └──────────┘ |
| 172 | +``` |
| 173 | + |
| 174 | +### zeros |
| 175 | +`zeros(N)` – Returns a table with the single `zero` column (uint8) that contains N zeros. |
| 176 | + |
| 177 | +### zeros_mt |
| 178 | +`zeros_mt(N)` – Returns a table with the single `zero` column (uint8) that contains N zeros, using multiple threads for faster generation. |
0 commit comments