暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

MogDB 视图原始DDL语句查询

原创 MogDB 2024-08-06
210

可获得性

本特性自MogDB 5.0.2版本开始引入。

特性简介

MogDB支持调用系统函数pg_get_ori_viewdef(view_name)来查询指定视图的原始DDL语句,同时可显示原始DDL语句中AS后的注释内容。

客户价值

客户可通过数据库查询视图的原始DDL语句。如果DDL语句中AS后有注释,也支持查询AS后的注释。

特性描述

MogDB新增了pg_get_ori_viewdef(view_name)函数通过视图名称来获取视图原始DDL语句,同时可显示原始DDL语句中AS后的注释内容,包括两种风格注释,即语句中带有--单行注释和/* */风格的注释。

示例

  1. 创建测试表,插入数据,并查询表。

    MogDB=# create table t_auto(a int, b int); CREATE TABLE MogDB=# insert into t_auto values(1,2); INSERT 0 1 MogDB=# select * from t_auto; a | b ---+--- 1 | 2 (1 row)
  2. 创建带- -单行注释和/* */注释的视图 。

    MogDB=# create /* line create*/ --line create MogDB-# or /* line or */ --line or MogDB-# replace /* line replace */ --line replace MogDB-# view /* line view */ --line view MogDB-# v1 /* line view_name */ --line view_name MogDB-# as /*line as */ --line as MogDB$# select /* line select */ --line select MogDB$# * /* line target */ --line target MogDB$# from /* line from */ --line from MogDB$# t_auto /* line rel */ --line rel MogDB$# ; CREATE VIEW
  3. 使用pg_get_ori_viewdef(view_name)函数查询视图。

    函数查询格式有以下两种:

    • select pg_get_ori_viewdef (‘view_name’):表示查询当前schema下的视图的原始DDL。

    • select pg_get_ori_viewdef (‘schema.view_name’):表示查询指定schema下的视图的原始DDL。

    MogDB=# select pg_get_ori_viewdef ('v1'); pg_get_ori_viewdef --------------------------------------------- CREATE OR REPLACE VIEW public.v1(a, b) AS + /*line as */ --line as + select /* line select */ --line select + * /* line target */ --line target + from /* line from */ --line from + t_auto /* line rel */ --line rel + ; (1 row)

特性增强

MogDB 5.0.6及以上版本的gs_dump和gs_dumpall工具均支持导出视图原始DDL语句。

相关页面

pg_get_ori_viewdef(view_name)gs_dumpgs_dumpall

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论