File: table-partition.txt

package info (click to toggle)
golang-ariga-atlas 0.7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 5,676 kB
  • sloc: javascript: 592; sql: 404; makefile: 10
file content (326 lines) | stat: -rw-r--r-- 8,309 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
apply 1.hcl
cmpshow logs 1.sql

# Changing partitioned table is not allowed.
! apply 2.hcl 'partition key of table "logs" cannot be changed from PARTITION BY LIST ("value") to PARTITION BY RANGE ("a", (b * (a % 2))) (drop and add is required)'

# Drop all tables.
apply drop.hcl

# Recreate partitioned table.
apply 2.hcl
cmpshow logs 2.sql

# Drop all tables.
apply drop.hcl

apply 3.hcl
cmpshow measurement 3.sql
cmphcl 3.inspect.hcl
execsql 'CREATE TABLE measurement_y2006m02 PARTITION OF $db.measurement FOR VALUES FROM (''2006-02-01'') TO (''2006-03-01'')'
cmpshow measurement 3.partition.sql

# Drop all tables.
apply drop.hcl

apply 4.hcl
cmpshow metrics 4.sql
cmphcl 4.inspect.hcl

-- 1.hcl --
schema "$db" {}

table "logs" {
  schema = schema.$db
  column "value" {
    null = false
    type = integer
  }
  partition {
    type = LIST
    columns = [column.value]
  }
}

-- postgres10/1.sql --
        Table "script_table_partition.logs"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 value  | integer |           | not null |
Partition key: LIST (value)

-- postgres11/1.sql --
        Table "script_table_partition.logs"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 value  | integer |           | not null |
Partition key: LIST (value)
Number of partitions: 0

-- 1.sql --
  Partitioned table "script_table_partition.logs"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 value  | integer |           | not null |
Partition key: LIST (value)
Number of partitions: 0

-- 2.hcl --
schema "$db" {}

table "logs" {
  schema = schema.$db
  column "a" {
    null = false
    type = integer
  }
  column "b" {
    null = false
    type = integer
  }
  partition {
    type = RANGE
    by {
      column = column.a
    }
    by {
      expr = "b * (a % 2)"
    }
  }
}

-- postgres10/2.sql --
        Table "script_table_partition.logs"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 a      | integer |           | not null |
 b      | integer |           | not null |
Partition key: RANGE (a, ((b * (a % 2))))

-- postgres11/2.sql --
        Table "script_table_partition.logs"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 a      | integer |           | not null |
 b      | integer |           | not null |
Partition key: RANGE (a, ((b * (a % 2))))
Number of partitions: 0

-- 2.sql --
  Partitioned table "script_table_partition.logs"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 a      | integer |           | not null |
 b      | integer |           | not null |
Partition key: RANGE (a, ((b * (a % 2))))
Number of partitions: 0

-- 3.hcl --
schema "$db" {}

# The partitioned table from the PostgreSQL doc.
table "measurement" {
  schema = schema.$db
  column "city_id" {
    null = false
    type = integer
  }
  column "logdate" {
    null = false
    type = date
  }
  column "peaktemp" {
    null = true
    type = int
  }
  column "unitsales" {
    null = true
    type = int
  }
  partition {
    type = RANGE
    columns = [column.logdate]
  }
}

-- postgres10/3.sql --
      Table "script_table_partition.measurement"
  Column   |  Type   | Collation | Nullable | Default
-----------+---------+-----------+----------+---------
 city_id   | integer |           | not null |
 logdate   | date    |           | not null |
 peaktemp  | integer |           |          |
 unitsales | integer |           |          |
Partition key: RANGE (logdate)

-- postgres11/3.sql --
      Table "script_table_partition.measurement"
  Column   |  Type   | Collation | Nullable | Default
-----------+---------+-----------+----------+---------
 city_id   | integer |           | not null |
 logdate   | date    |           | not null |
 peaktemp  | integer |           |          |
 unitsales | integer |           |          |
Partition key: RANGE (logdate)
Number of partitions: 0

-- 3.sql --
Partitioned table "script_table_partition.measurement"
  Column   |  Type   | Collation | Nullable | Default
-----------+---------+-----------+----------+---------
 city_id   | integer |           | not null |
 logdate   | date    |           | not null |
 peaktemp  | integer |           |          |
 unitsales | integer |           |          |
Partition key: RANGE (logdate)
Number of partitions: 0


-- postgres10/3.partition.sql --
      Table "script_table_partition.measurement"
  Column   |  Type   | Collation | Nullable | Default
-----------+---------+-----------+----------+---------
 city_id   | integer |           | not null |
 logdate   | date    |           | not null |
 peaktemp  | integer |           |          |
 unitsales | integer |           |          |
Partition key: RANGE (logdate)
Number of partitions: 1 (Use \d+ to list them.)

-- postgres11/3.partition.sql --
      Table "script_table_partition.measurement"
  Column   |  Type   | Collation | Nullable | Default
-----------+---------+-----------+----------+---------
 city_id   | integer |           | not null |
 logdate   | date    |           | not null |
 peaktemp  | integer |           |          |
 unitsales | integer |           |          |
Partition key: RANGE (logdate)
Number of partitions: 1 (Use \d+ to list them.)

-- 3.partition.sql --
Partitioned table "script_table_partition.measurement"
  Column   |  Type   | Collation | Nullable | Default
-----------+---------+-----------+----------+---------
 city_id   | integer |           | not null |
 logdate   | date    |           | not null |
 peaktemp  | integer |           |          |
 unitsales | integer |           |          |
Partition key: RANGE (logdate)
Number of partitions: 1 (Use \d+ to list them.)

-- 3.inspect.hcl --
table "measurement" {
  schema = schema.script_table_partition
  column "city_id" {
    null = false
    type = integer
  }
  column "logdate" {
    null = false
    type = date
  }
  column "peaktemp" {
    null = true
    type = integer
  }
  column "unitsales" {
    null = true
    type = integer
  }
  partition {
    type    = RANGE
    columns = [column.logdate]
  }
}
schema "script_table_partition" {
}

-- 4.hcl --
schema "$db" {}

table "metrics" {
  schema = schema.$db
  column "x" {
    null = false
    type = integer
  }
  column "y" {
    null = false
    type = integer
  }
  partition {
    type = RANGE
    by {
        column = column.x
    }
    by {
        expr = "floor(x)"
    }
    by {
        expr = "y * 2"
    }
    by {
        expr = "floor(y)"
    }
  }
}

-- postgres10/4.sql --
      Table "script_table_partition.metrics"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 x      | integer |           | not null |
 y      | integer |           | not null |
Partition key: RANGE (x, floor((x)::double precision), ((y * 2)), floor((y)::double precision))

-- postgres11/4.sql --
      Table "script_table_partition.metrics"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 x      | integer |           | not null |
 y      | integer |           | not null |
Partition key: RANGE (x, floor((x)::double precision), ((y * 2)), floor((y)::double precision))
Number of partitions: 0

-- 4.sql --
Partitioned table "script_table_partition.metrics"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 x      | integer |           | not null |
 y      | integer |           | not null |
Partition key: RANGE (x, floor((x)::double precision), ((y * 2)), floor((y)::double precision))
Number of partitions: 0

-- 4.inspect.hcl --
table "metrics" {
  schema = schema.script_table_partition
  column "x" {
    null = false
    type = integer
  }
  column "y" {
    null = false
    type = integer
  }
  partition {
    type = RANGE
    by {
      column = column.x
    }
    by {
      expr = "floor((x)::double precision)"
    }
    by {
      expr = "(y * 2)"
    }
    by {
      expr = "floor((y)::double precision)"
    }
  }
}
schema "script_table_partition" {
}

-- drop.hcl --
schema "$db" {}