2023-11-12 20:14:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								--PGSQL_DB_SCHEMAS 库schemas
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								select
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									n.nspname as "schemaName"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								from
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									pg_namespace n
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								where
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									has_schema_privilege(n.nspname, 'USAGE')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									and n.nspname not like 'pg_%'
							 | 
						
					
						
							
								
									
										
										
										
											2023-12-19 19:23:33 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    and n.nspname not like 'dbms_%'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    and n.nspname not like 'utl_%'
							 | 
						
					
						
							
								
									
										
										
										
											2023-11-12 20:14:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									and n.nspname != 'information_schema'
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-15 11:55:59 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								order by
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    n.nspname
							 | 
						
					
						
							
								
									
										
										
										
											2023-11-12 20:14:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								---------------------------------------
							 | 
						
					
						
							
								
									
										
										
										
											2023-05-24 12:32:17 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								--PGSQL_TABLE_INFO 表详细信息
							 | 
						
					
						
							
								
									
										
										
										
											2023-11-02 12:46:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								select
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									c.relname as "tableName",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									obj_description (c.oid) as "tableComment",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									pg_table_size ('"' || n.nspname || '"."' || c.relname || '"') as "dataLength",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									pg_indexes_size ('"' || n.nspname || '"."' || c.relname || '"') as "indexLength",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									psut.n_live_tup as "tableRows"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								from
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									pg_class c
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								join pg_namespace n on
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									c.relnamespace = n.oid
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								join pg_stat_user_tables psut on
							 | 
						
					
						
							
								
									
										
										
										
											2023-11-12 20:14:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									psut.relid = c.oid
							 | 
						
					
						
							
								
									
										
										
										
											2023-11-02 12:46:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								where
							 | 
						
					
						
							
								
									
										
										
										
											2023-11-12 20:14:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    has_table_privilege(CAST(c.oid AS regclass), 'SELECT')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									and n.nspname = current_schema()
							 | 
						
					
						
							
								
									
										
										
										
											2023-11-02 12:46:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									and c.reltype > 0
							 | 
						
					
						
							
								
									
										
										
										
											2024-03-18 12:25:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    {{if .tableNames}}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        and c.relname in ({{.tableNames}})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    {{end}}
							 | 
						
					
						
							
								
									
										
										
										
											2024-03-15 09:01:51 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								order by c.relname
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								---------------------------------------
							 | 
						
					
						
							
								
									
										
										
										
											2023-05-24 12:32:17 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								--PGSQL_INDEX_INFO 表索引信息
							 | 
						
					
						
							
								
									
										
										
										
											2024-03-26 09:05:28 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								SELECT indexname                                                         AS "indexName",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       'BTREE'                                                           AS "IndexType",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       case when indexdef like 'CREATE UNIQUE INDEX%%' then 1 else 0 end as "isUnique",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       obj_description(b.oid, 'pg_class')                                AS "indexComment",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       indexdef                                                          AS "indexDef",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       c.attname                                                         AS "columnName",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       c.attnum                                                          AS "seqInIndex",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       case when indexname like '%_pkey' then 1 else 0 end               as "isPrimaryKey"
							 | 
						
					
						
							
								
									
										
										
										
											2023-11-23 10:36:20 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								FROM pg_indexes a
							 | 
						
					
						
							
								
									
										
										
										
											2024-03-26 09:05:28 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         join pg_class b on a.indexname = b.relname
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         join pg_attribute c on b.oid = c.attrelid
							 | 
						
					
						
							
								
									
										
										
										
											2023-11-23 10:36:20 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								WHERE a.schemaname = (select current_schema())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  AND a.tablename = '%s';
							 | 
						
					
						
							
								
									
										
										
										
											2023-06-17 16:04:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								---------------------------------------
							 | 
						
					
						
							
								
									
										
										
										
											2023-05-24 12:32:17 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								--PGSQL_COLUMN_MA 表列信息
							 | 
						
					
						
							
								
									
										
										
										
											2024-03-26 09:05:28 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								SELECT a.table_name                                                                            AS "tableName",
							 | 
						
					
						
							
								
									
										
										
										
											2024-03-21 03:35:18 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								       a.column_name                                                                           AS "columnName",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       a.is_nullable                                                                           AS "nullable",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       a.udt_name                                                                              AS "dataType",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       a.character_maximum_length                                                              AS "charMaxLength",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       a.numeric_precision                                                                     AS "numPrecision",
							 | 
						
					
						
							
								
									
										
										
										
											2024-03-26 09:05:28 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								       case when a.column_default like 'nextval%%' then null else a.column_default end         AS "columnDefault",
							 | 
						
					
						
							
								
									
										
										
										
											2024-03-21 03:35:18 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								       a.numeric_scale                                                                         AS "numScale",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       case when a.column_default like 'nextval%%' then 1 else 0 end                           AS "isIdentity",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       case when b.column_name is not null then 1 else 0 end                                   AS "isPrimaryKey",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       col_description((a.table_schema || '.' || a.table_name) ::regclass, a.ordinal_position) AS "columnComment"
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-29 04:20:23 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								FROM information_schema.columns a
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         left join information_schema.key_column_usage b
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                   on a.table_schema = b.table_schema and b.table_name = a.table_name and b.column_name = a.column_name
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								WHERE a.table_schema = (select current_schema())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  and a.table_name in (%s)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								order by a.table_name, a.ordinal_position
							 |