From 5afda5e7427debd35062cf656f479951d08fda17 Mon Sep 17 00:00:00 2001 From: Kexiang Wang Date: Fri, 13 Dec 2024 11:54:51 -0500 Subject: [PATCH] =?UTF-8?q?feat(catalog):=20add=20pg=5Fmy=5Ftemp=5Fschema?= =?UTF-8?q?=20and=20pg=5Fget=5Fviewdef(int4,=20bool=E2=80=A6=20(#19750)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- e2e_test/batch/catalog/sysinfo.slt.part | 10 ++++++++++ .../src/binder/expr/function/builtin_scalar.rs | 7 +++++++ .../src/catalog/system_catalog/pg_catalog/pg_proc.rs | 1 + src/frontend/src/expr/function_impl/pg_get_viewdef.rs | 5 +++++ 4 files changed, 23 insertions(+) diff --git a/e2e_test/batch/catalog/sysinfo.slt.part b/e2e_test/batch/catalog/sysinfo.slt.part index 5c9aea2fb6103..ea3a3654804e5 100644 --- a/e2e_test/batch/catalog/sysinfo.slt.part +++ b/e2e_test/batch/catalog/sysinfo.slt.part @@ -70,6 +70,16 @@ select pg_get_viewdef('tab_mv'::regclass); ---- SELECT a.c AS ac, b.c AS bc FROM tab AS a JOIN tab AS b ON a.a = b.b +query T +select pg_get_viewdef('tab_mv'::regclass, false); +---- +SELECT a.c AS ac, b.c AS bc FROM tab AS a JOIN tab AS b ON a.a = b.b + +query T +select pg_get_viewdef('tab_mv'::regclass, true); +---- +SELECT a.c AS ac, b.c AS bc FROM tab AS a JOIN tab AS b ON a.a = b.b + query error Invalid parameter oid: view or materialized view does not exist: select pg_get_viewdef('tab'::regclass); diff --git a/src/frontend/src/binder/expr/function/builtin_scalar.rs b/src/frontend/src/binder/expr/function/builtin_scalar.rs index 56c35ba66b004..ff529eba747e3 100644 --- a/src/frontend/src/binder/expr/function/builtin_scalar.rs +++ b/src/frontend/src/binder/expr/function/builtin_scalar.rs @@ -533,6 +533,13 @@ impl Binder { .into()) } })), + ("pg_my_temp_schema", guard_by_len(0, raw(|_binder, _inputs| { + // Returns the OID of the current session's temporary schema, or zero if it has none (because it has not created any temporary tables). + Ok(ExprImpl::literal_int( + // always return 0, as we haven't supported temporary tables nor temporary schema yet + 0, + )) + }))), ("current_setting", guard_by_len(1, raw(|binder, inputs| { let input = &inputs[0]; let input = if let ExprImpl::Literal(literal) = input && diff --git a/src/frontend/src/catalog/system_catalog/pg_catalog/pg_proc.rs b/src/frontend/src/catalog/system_catalog/pg_catalog/pg_proc.rs index 2f2abce7a0b8e..d23d7ea933168 100644 --- a/src/frontend/src/catalog/system_catalog/pg_catalog/pg_proc.rs +++ b/src/frontend/src/catalog/system_catalog/pg_catalog/pg_proc.rs @@ -31,4 +31,5 @@ struct PgProc { // Data type of the return value, refer to pg_type. prorettype: i32, prokind: String, + proargtypes: Vec, } diff --git a/src/frontend/src/expr/function_impl/pg_get_viewdef.rs b/src/frontend/src/expr/function_impl/pg_get_viewdef.rs index fda4eb961501c..413af0626d163 100644 --- a/src/frontend/src/expr/function_impl/pg_get_viewdef.rs +++ b/src/frontend/src/expr/function_impl/pg_get_viewdef.rs @@ -24,6 +24,11 @@ use crate::catalog::CatalogReader; #[function("pg_get_viewdef(int4) -> varchar")] fn pg_get_viewdef(oid: i32, writer: &mut impl Write) -> Result<()> { + pg_get_viewdef_pretty(oid, false, writer) +} + +#[function("pg_get_viewdef(int4, boolean) -> varchar")] +fn pg_get_viewdef_pretty(oid: i32, _pretty: bool, writer: &mut impl Write) -> Result<()> { pg_get_viewdef_impl_captured(oid, writer) }