Skip to content

Commit

Permalink
feat(catalog): add pg_my_temp_schema and pg_get_viewdef(int4, bool… (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
KeXiangWang authored Dec 13, 2024
1 parent bfef38e commit 5afda5e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions e2e_test/batch/catalog/sysinfo.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 7 additions & 0 deletions src/frontend/src/binder/expr/function/builtin_scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ struct PgProc {
// Data type of the return value, refer to pg_type.
prorettype: i32,
prokind: String,
proargtypes: Vec<i32>,
}
5 changes: 5 additions & 0 deletions src/frontend/src/expr/function_impl/pg_get_viewdef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 5afda5e

Please sign in to comment.