1#include "duckdb/parser/statement/pragma_statement.hpp"
2#include "duckdb/parser/transformer.hpp"
3#include "duckdb/parser/statement/show_statement.hpp"
4#include "duckdb/parser/query_node/select_node.hpp"
5#include "duckdb/parser/expression/star_expression.hpp"
6#include "duckdb/parser/tableref/basetableref.hpp"
7
8namespace duckdb {
9
10static void TransformShowName(unique_ptr<PragmaStatement> &result, const string &name) {
11 auto &info = *result->info;
12 auto lname = StringUtil::Lower(str: name);
13
14 if (lname == "\"databases\"") {
15 info.name = "show_databases";
16 } else if (lname == "\"tables\"") {
17 // show all tables
18 info.name = "show_tables";
19 } else if (lname == "__show_tables_expanded") {
20 info.name = "show_tables_expanded";
21 } else {
22 // show one specific table
23 info.name = "show";
24 info.parameters.emplace_back(args: name);
25 }
26}
27
28unique_ptr<SQLStatement> Transformer::TransformShow(duckdb_libpgquery::PGVariableShowStmt &stmt) {
29 // we transform SHOW x into PRAGMA SHOW('x')
30 if (stmt.is_summary) {
31 auto result = make_uniq<ShowStatement>();
32 auto &info = *result->info;
33 info.is_summary = stmt.is_summary;
34
35 auto select = make_uniq<SelectNode>();
36 select->select_list.push_back(x: make_uniq<StarExpression>());
37 auto basetable = make_uniq<BaseTableRef>();
38 auto qualified_name = QualifiedName::Parse(input: stmt.name);
39 basetable->schema_name = qualified_name.schema;
40 basetable->table_name = qualified_name.name;
41 select->from_table = std::move(basetable);
42
43 info.query = std::move(select);
44 return std::move(result);
45 }
46
47 auto result = make_uniq<PragmaStatement>();
48
49 auto show_name = stmt.name;
50 TransformShowName(result, name: show_name);
51 return std::move(result);
52}
53
54} // namespace duckdb
55