-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathALL_TAB_PARTITIONS.sql
More file actions
62 lines (56 loc) · 1.7 KB
/
ALL_TAB_PARTITIONS.sql
File metadata and controls
62 lines (56 loc) · 1.7 KB
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
CREATE OR REPLACE VIEW "ALL_TAB_PARTITIONS" AS
SELECT
ns.nspname AS "TABLE_OWNER",
parent.relname AS "TABLE_NAME",
child.relname AS "PARTITION_NAME",
-- Oracle-style partition position
ROW_NUMBER() OVER (
PARTITION BY parent.oid
ORDER BY child.oid
) AS "PARTITION_POSITION",
-- Oracle-style HIGH_VALUE (upper bound only, no quotes)
CASE
WHEN pg_get_expr(child.relpartbound, child.oid) ~ 'TO \(MAXVALUE\)'
THEN 'MAXVALUE'
ELSE trim(
BOTH ''''
FROM regexp_replace(
pg_get_expr(child.relpartbound, child.oid),
'.*TO \((.*)\)$',
'\1'
)
)
END AS "HIGH_VALUE",
-- Length of HIGH_VALUE (Oracle compatibility)
LENGTH(
CASE
WHEN pg_get_expr(child.relpartbound, child.oid) ~ 'TO \(MAXVALUE\)'
THEN 'MAXVALUE'
ELSE trim(
BOTH ''''
FROM regexp_replace(
pg_get_expr(child.relpartbound, child.oid),
'.*TO \((.*)\)$',
'\1'
)
)
END
) AS "HIGH_VALUE_LENGTH",
-- Partitioning type (Oracle naming)
CASE pt.partstrat
WHEN 'r' THEN 'RANGE'
WHEN 'l' THEN 'LIST'
WHEN 'h' THEN 'HASH'
END AS "PARTITIONING_TYPE",
-- Number of partition key columns
pt.partnatts AS "PARTITION_KEY_COUNT"
FROM pg_inherits i
JOIN pg_class parent
ON parent.oid = i.inhparent
JOIN pg_class child
ON child.oid = i.inhrelid
JOIN pg_namespace ns
ON ns.oid = parent.relnamespace
JOIN pg_partitioned_table pt
ON pt.partrelid = parent.oid
WHERE parent.relkind = 'p';