risingwave_frontend/catalog/system_catalog/information_schema/
columns.rs

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
// Copyright 2024 RisingWave Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use risingwave_common::types::Fields;
use risingwave_frontend_macro::system_catalog;

/// The view `columns` contains information about all table columns (or view columns) in the
/// database. System columns (ctid, etc.) are not included. Only those columns are shown that the
/// current user has access to (by way of being the owner or having some privilege).
/// Ref: [`https://www.postgresql.org/docs/current/infoschema-columns.html`]
///
/// In RisingWave, `columns` also contains all materialized views' columns.
#[system_catalog(
    view,
    "information_schema.columns",
    "SELECT CURRENT_DATABASE() AS table_catalog,
        s.name AS table_schema,
        r.name AS table_name,
        c.name AS column_name,
        NULL AS column_default,
        NULL::integer AS character_maximum_length,
        NULL::integer AS numeric_precision,
        NULL::integer AS numeric_precision_radix,
        NULL::integer AS numeric_scale,
        NULL::integer AS datetime_precision,
        c.position AS ordinal_position,
        'YES' AS is_nullable,
        CASE
            WHEN c.data_type = 'varchar' THEN 'character varying'
            ELSE c.data_type
        END AS data_type,
        CURRENT_DATABASE() AS udt_catalog,
        'pg_catalog' AS udt_schema,
        c.udt_type AS udt_name,
        NULL AS character_set_catalog,
        NULL AS character_set_schema,
        NULL AS character_set_name,
        NULL AS collation_catalog,
        NULL AS collation_schema,
        NULL AS collation_name,
        NULL AS domain_catalog,
        NULL AS domain_schema,
        NULL AS domain_name,
        NULL AS scope_catalog,
        NULL AS scope_schema,
        NULL AS scope_name,
        'NO' AS is_identity,
        NULL AS identity_generation,
        NULL AS identity_start,
        NULL AS identity_increment,
        NULL AS identity_maximum,
        NULL AS identity_minimum,
        NULL AS identity_cycle,
        CASE
            WHEN c.is_generated THEN 'ALWAYS'
            ELSE 'NEVER'
        END AS is_generated,
        c.generation_expression,
        NULL AS interval_type
    FROM rw_catalog.rw_columns c
    LEFT JOIN rw_catalog.rw_relations r ON c.relation_id = r.id
    JOIN rw_catalog.rw_schemas s ON s.id = r.schema_id
    WHERE c.is_hidden = false"
)]
#[derive(Fields)]
struct Column {
    table_catalog: String,
    table_schema: String,
    table_name: String,
    column_name: String,
    column_default: String,
    character_maximum_length: i32,
    numeric_precision: i32,
    numeric_precision_radix: i32,
    numeric_scale: i32,
    datetime_precision: i32,
    ordinal_position: i32,
    is_nullable: String,
    data_type: String,
    udt_catalog: String,
    udt_schema: String,
    udt_name: String,
    character_set_catalog: String,
    character_set_schema: String,
    character_set_name: String,
    collation_catalog: String,
    collation_schema: String,
    collation_name: String,
    domain_catalog: String,
    domain_schema: String,
    domain_name: String,
    scope_catalog: String,
    scope_schema: String,
    scope_name: String,
    is_identity: String,
    identity_generation: String,
    identity_start: String,
    identity_increment: String,
    identity_maximum: String,
    identity_minimum: String,
    identity_cycle: String,
    is_generated: String,
    generation_expression: String,
    interval_type: String,
}