国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

PostgreSQL 查詢數(shù)據(jù)表、視圖信息

這篇具有很好參考價值的文章主要介紹了PostgreSQL 查詢數(shù)據(jù)表、視圖信息。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

--獲得指定schema范圍內(nèi)的所有表和視圖的列表,可指定一個排除表前綴模式
with param as (select 'public,iit' as schema_name,'db2g%' as exclude_pattern)
    ,base_info as (
        --獲得所有基表
        select pg_namespace.nspname as schema_name, a.relname as tbl_name ,'TBL' as tbl_type, b.description as tbl_comment
        from pg_class a
            join pg_namespace on a.relnamespace=pg_namespace.oid
            left join (select * from pg_description where objsubid =0 ) b
                on a.oid = b.objoid
        where a.relkind='r'
             and a.relname not like (select exclude_pattern from param)
             and pg_namespace.nspname in (select regexp_split_to_table(schema_name,',') from param)
        union all
        ---獲取所有視圖
        SELECT schemaname as schema_name, viewname as tbl_name,'VW' as tbl_type, null as tbl_comment
        FROM pg_views
        WHERE schemaname in (select regexp_split_to_table(schema_name,',') from param)
    )
select * from base_info;
--獲得指定schema范圍內(nèi)的所有表和視圖的數(shù)據(jù)列信息,可指定一個排除表前綴模式
with param as (select 'public,iit' as schema_name,'db2g%' as exclude_pattern),
     base_info as (
         select table_schema
              , table_name
              , ordinal_position                                                      as Colorder
              , column_name                                                           as ColumnName
              , data_type                                                             as TypeName
              , coalesce(character_maximum_length, numeric_precision, -1)             as Length
              , numeric_scale                                                         as Scale
              , case is_nullable when 'NO' then 0 else 1 end                          as CanNull
              , column_default                                                        as DefaultVal
              , case when position('nextval' in column_default) > 0 then 1 else 0 end as IsIdentity
              , case when b.pk_name is null then 0 else 1 end                         as IsPK
              , c.DeText
         from information_schema.columns
                  left join (
                             select pg_attr.attname as colname
                                    ,pg_constraint.conname as pk_name
                                    ,pg_class.relname as tblname
                                    ,pg_namespace.nspname as schema_name
                             from pg_constraint
                                      join pg_class on pg_constraint.conrelid = pg_class.oid
                                      join pg_attribute pg_attr on pg_attr.attrelid = pg_class.oid
                                            and pg_attr.attnum = pg_constraint.conkey[1]
                                      join pg_type on pg_type.oid = pg_attr.atttypid
                                      join pg_namespace on pg_constraint.connamespace=pg_namespace.oid
                             where pg_constraint.contype = 'p'
                            ) b on b.colname = information_schema.columns.column_name
                                    and b.tblname=information_schema.columns.table_name
                                    and b.schema_name=information_schema.columns.table_schema
                  left join (
                             select attname, description as DeText, pg_class.relname as tblname,pg_namespace.nspname as schema_name
                             from pg_class
                                      join pg_namespace on pg_class.relnamespace=pg_namespace.oid
                                      left join pg_attribute pg_attr on pg_attr.attrelid = pg_class.oid
                                      left join pg_description pg_desc on pg_desc.objoid = pg_attr.attrelid
                                 and pg_desc.objsubid = pg_attr.attnum
                             where pg_attr.attnum > 0
                               and pg_attr.attrelid = pg_class.oid
                         ) c on c.attname = information_schema.columns.column_name
                                and c.tblname=information_schema.columns.table_name
                                and c.schema_name=information_schema.columns.table_schema
         where table_schema in (select regexp_split_to_table(schema_name,',') from param)
              and table_name not like (select exclude_pattern from param)
         order by table_name,ordinal_position
     )
select * from base_info;
--查詢指定模式下的表和視圖

with param as (select 'public' as schema_name,'db2g%' as exclude_pattern)
--獲得所有基表
select a.relname as tbl_name ,'TBL' as tbl_type, b.description as tbl_comment
from pg_class a
    left join (select *
                from pg_description where objsubid =0 ) b
        on a.oid = b.objoid
where a.relname in (select tablename
                    from pg_tables
                    where schemaname = (select schema_name from param))
     and a.relname not like (select exclude_pattern from param)
union all
---獲取所有視圖
SELECT viewname as tbl_name,'VW' as tbl_type, null as tbl_comment
FROM pg_views
WHERE schemaname =(select schema_name from param)
order by tbl_name asc;

--查詢指定數(shù)據(jù)基表的列信息文章來源地址http://www.zghlxwxcb.cn/news/detail-660720.html

with param as (select 'emp' as tblname),
     base_info as (
         select ordinal_position                                                      as Colorder
              , column_name                                                           as ColumnName
              , data_type                                                             as TypeName
              , coalesce(character_maximum_length, numeric_precision, -1)             as Length
              , numeric_scale                                                         as Scale
              , case is_nullable when 'NO' then 0 else 1 end                          as CanNull
              , column_default                                                        as DefaultVal
              , case when position('nextval' in column_default) > 0 then 1 else 0 end as IsIdentity
              , case when b.pk_name is null then 0 else 1 end                         as IsPK
              , c.DeText
         from information_schema.columns
                  left join (
                             select pg_attr.attname as colname, pg_constraint.conname as pk_name
                             from pg_constraint
                                      join pg_class on pg_constraint.conrelid = pg_class.oid
                                      join pg_attribute pg_attr on pg_attr.attrelid = pg_class.oid
                                 and pg_attr.attnum = pg_constraint.conkey[1]
                                      join pg_type on pg_type.oid = pg_attr.atttypid
                             where pg_class.relname = (select tblname from param)
                               and pg_constraint.contype = 'p'
                            ) b on b.colname = information_schema.columns.column_name
                  left join (
             select attname, description as DeText
             from pg_class
                      left join pg_attribute pg_attr on pg_attr.attrelid = pg_class.oid
                      left join pg_description pg_desc on pg_desc.objoid = pg_attr.attrelid
                 and pg_desc.objsubid = pg_attr.attnum
             where pg_attr.attnum > 0
               and pg_attr.attrelid = pg_class.oid
               and pg_class.relname = (select tblname from param)
         ) c on c.attname = information_schema.columns.column_name
         where table_schema = 'public'
           and table_name = (select tblname from param)
         order by ordinal_position asc
     )
select * from base_info

到了這里,關(guān)于PostgreSQL 查詢數(shù)據(jù)表、視圖信息的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • SQL Server多數(shù)據(jù)表之間的數(shù)據(jù)查詢和分組查詢

    SQL Server多數(shù)據(jù)表之間的數(shù)據(jù)查詢和分組查詢

    在SQL中,多數(shù)據(jù)表之間的查詢主要用于以下方面: 在SQL Server中,多數(shù)據(jù)表之間的數(shù)據(jù)查詢主要用于以下幾個方面: 關(guān)聯(lián)數(shù)據(jù)提取 :現(xiàn)代數(shù)據(jù)庫通常將數(shù)據(jù)分散在多個相關(guān)的表中以便于管理。例如,訂單信息可能存儲在一個表中,而客戶信息可能存儲在另一個表中。為了獲取

    2024年01月24日
    瀏覽(32)
  • HBase數(shù)據(jù)表查詢操作和獲取多版本數(shù)據(jù)

    HBase數(shù)據(jù)模型是一個多維稀疏映射。 HBase中的表包含列族,其列限定符包含值和時間戳。在大多數(shù) HappyBase API 中,列族和限定符名稱被指定為單個字符串,例如cf1:col1,而不是作為兩個單獨的參數(shù)。雖然列族和限定符在 HBase 數(shù)據(jù)模型中是不同的概念,但它們在與數(shù)據(jù)交互時幾

    2024年02月15日
    瀏覽(23)
  • PostgreSQL-視圖-03-查詢對象依賴關(guān)系視圖-dba_dependencies

    PostgreSQL查詢對象依賴關(guān)系視圖

    2024年02月15日
    瀏覽(25)
  • MySQL數(shù)據(jù)庫——MySQL SELECT:數(shù)據(jù)表查詢語句

    在?MySQL 中,可以使用 SELECT 語句來查詢數(shù)據(jù)。查詢數(shù)據(jù)是指從數(shù)據(jù)庫中根據(jù)需求,使用不同的查詢方式來獲取不同的數(shù)據(jù),是使用頻率最高、最重要的操作。 SELECT 的語法格式如下: 其中,各條子句的含義如下: {*|字段列名} 包含星號通配符的字段列表,表示所要查詢字段的

    2024年02月05日
    瀏覽(232)
  • SQL Server 數(shù)據(jù)表模糊查詢(like 用法)以及查詢函數(shù)

    在SQL Server Management Studio (SSMS) 中,進(jìn)行模糊查詢主要是通過使用 like 操作符來實現(xiàn)的。 like 操作符用于在 where 語句中搜索列中具有指定模式的數(shù)據(jù)。 我們在簡單例子中來了解: % 通配符:表示任意數(shù)量的字符。 這個例子會選擇 column_name 列中包含\\\"pattern\\\"這個詞的所有記錄,就

    2024年01月22日
    瀏覽(53)
  • Mysql 查詢數(shù)據(jù)庫或數(shù)據(jù)表中的數(shù)據(jù)量以及數(shù)據(jù)大小

    ?許多數(shù)據(jù)庫的元數(shù)據(jù)都是存儲在mysql中的,例如hive、startrockes,因此可以通過mysql中的“information_schema.TABLES”表來查詢對應(yīng)數(shù)據(jù)庫或?qū)?yīng)數(shù)據(jù)表的具體信息。 1、查詢各個數(shù)據(jù)庫中的數(shù)據(jù)條數(shù)和數(shù)據(jù)大小 2、查詢各個數(shù)據(jù)表中的數(shù)據(jù)條數(shù)和數(shù)據(jù)大小 3、查看指定數(shù)據(jù)庫容量大小

    2024年04月27日
    瀏覽(96)
  • 8-MySQL查詢高級用法,數(shù)據(jù)表的關(guān)聯(lián)關(guān)系

    8-MySQL查詢高級用法,數(shù)據(jù)表的關(guān)聯(lián)關(guān)系

    1.分組 group by 詳情見,發(fā)布的第七篇博客文章,7- MySQL函數(shù) 2.排序 order by 說明: 在MySQL中,ORDER BY是一種用于對查詢結(jié)果進(jìn)行排序的。它可以根據(jù)一列或多列的值,以升序或降序的方式對查詢結(jié)果進(jìn)行排序,使得查詢者可以更加方便 地查看、分析和處理數(shù)據(jù)。 使用OR

    2024年02月08日
    瀏覽(29)
  • SQL學(xué)習(xí)(六)--DML(針對數(shù)據(jù)表記錄的查詢操作)

    目錄 一、 單表查詢 小拓展: 數(shù)據(jù)準(zhǔn)備: 1.? ?查詢整張表的數(shù)據(jù)

    2023年04月27日
    瀏覽(22)
  • 查詢Oracle當(dāng)前用戶下,所有數(shù)據(jù)表的總條數(shù)

    查詢Oracle當(dāng)前用戶下,所有數(shù)據(jù)表的總條數(shù)

    查詢Oracle當(dāng)前用戶下,所有數(shù)據(jù)表的總條數(shù) 方法1:存儲過程 (文末有方法2,一個SQL也可輕松搞定!) 右鍵點擊 Procedures ,點擊 New 點擊 OK 把存儲過程寫進(jìn)去,然后點擊編譯運行: 3.2.1 方法一 方法2 點擊File -- New -- Test Window 寫入剛剛新增的存儲過程 方法2:SQL select sum(t.NUM_RO

    2024年02月12日
    瀏覽(29)
  • MySQL大數(shù)據(jù)表處理的三種方案,查詢效率嘎嘎高

    MySQL大數(shù)據(jù)表處理的三種方案,查詢效率嘎嘎高

    場景 當(dāng)我們業(yè)務(wù)數(shù)據(jù)庫表中的數(shù)據(jù)越來越多,如果你也和我遇到了以下類似場景,那讓我們一起來解決這個問題 數(shù)據(jù)的插入,查詢時長較長 后續(xù)業(yè)務(wù)需求的擴(kuò)展 在表中新增字段 影響較大 表中的數(shù)據(jù)并不是所有的都為有效數(shù)據(jù) 需求只查詢時間區(qū)間內(nèi)的 評估表數(shù)據(jù)體量 我們可

    2024年02月13日
    瀏覽(20)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包