我需要从数据库中的所有表连接一些列信息,我发现这个选择
SELECT 'postgresql' AS dbms,
t.table_catalog,t.table_schema,
t.table_name,c.column_name,
c.ordinal_position,c.data_type,
c.character_maximum_length,
n.constraint_type,
k2.table_schema,
k2.table_name,
k2.column_name
FROM information_schema.tables t
NATURAL LEFT JOIN information_schema.columns c
LEFT JOIN(
information_schema.key_column_usage k
NATURAL JOIN information_schema.table_constraints n
NATURAL LEFT JOIN information_schema.referential_constraints r)
ON c.table_catalog=k.table_catalog
AND c.table_schema=k.table_schema
AND c.table_name=k.table_name
AND c.column_name=k.column_name
LEFT JOIN information_schema.key_column_usage k2
ON k.position_in_unique_constraint=k2.ordinal_position
AND r.unique_constraint_catalog=k2.constraint_catalog
AND r.unique_constraint_schema=k2.constraint_schema
AND r.unique_constraint_name=k2.constraint_name
WHERE t.TABLE_TYPE='BASE TABLE' AND t.table_schema NOT IN('information_schema','pg_catalog')
ORDER BY t.table_name;
此查询提供了大量信息,但我需要所有列名称的描述。
我发现这个其他查询向我展示了描述
SELECT *
FROM pg_catalog.pg_statio_all_tables as st
inner join pg_catalog.pg_description pgd on (pgd.objoid=st.relid)
inner join information_schema.columns c on (pgd.objsubid=c.ordinal_position
and c.table_schema=st.schemaname and c.table_name=st.relname);
问题是如何将第二个查询中的字段 pgd.description 插入到第一个查询中。
谢谢和问候 授予Curro
答案 0 :(得分:0)
它们是两组不同的元数据函数:第一组使用通用的information_schema,而第二组使用PostgreSQL的特定系统函数。可以通过从information_schema表中的schema和tablename获取对象id(oid)来加入它们:
BufferedImage image = ImageIO.read(new File("blankdocument.bmp"));
Graphics g = ((BufferedImage) image).getGraphics();
Font helvetica = new Font("Lucida Sans Unicode", Font.PLAIN, 13);
g.setColor(Color.black);
g.setFont(helvetica);
g.drawString("TEXT WRITING EXAMPLE.", 5, 10);
ImageIO.write(image, "PNG", new File("testx.PNG"));
image.flush();