|
| 1 | +// Copyright 2023 RisingWave Labs |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +use std::sync::LazyLock; |
| 16 | + |
| 17 | +use risingwave_common::catalog::INFORMATION_SCHEMA_SCHEMA_NAME; |
| 18 | +use risingwave_common::types::DataType; |
| 19 | + |
| 20 | +use crate::catalog::system_catalog::BuiltinView; |
| 21 | + |
| 22 | +/// The view `views` contains all views defined in the current database. Only those views |
| 23 | +/// are shown that the current user has access to (by way of being the owner or having |
| 24 | +/// some privilege). |
| 25 | +/// Ref: [`https://www.postgresql.org/docs/current/infoschema-views.html`] |
| 26 | +/// |
| 27 | +/// In RisingWave, `views` contains information about defined views. |
| 28 | +pub static INFORMATION_SCHEMA_VIEWS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView { |
| 29 | + name: "views", |
| 30 | + schema: INFORMATION_SCHEMA_SCHEMA_NAME, |
| 31 | + columns: &[ |
| 32 | + (DataType::Varchar, "table_catalog"), |
| 33 | + (DataType::Varchar, "table_schema"), |
| 34 | + (DataType::Varchar, "table_name"), |
| 35 | + (DataType::Varchar, "view_definition"), |
| 36 | + ], |
| 37 | + sql: "SELECT CURRENT_DATABASE() AS table_catalog, \ |
| 38 | + s.name AS table_schema, \ |
| 39 | + v.name AS table_name, \ |
| 40 | + v.definition AS view_definition \ |
| 41 | + FROM rw_catalog.rw_views v \ |
| 42 | + JOIN rw_catalog.rw_schemas s ON v.schema_id = s.id \ |
| 43 | + ORDER BY table_schema, table_name" |
| 44 | + .to_string(), |
| 45 | +}); |
0 commit comments