显示查询结果列类型(PostgreSQL) [英] Show query result column types (PostgreSQL)

查看:266
本文介绍了显示查询结果列类型(PostgreSQL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以轻松获取查询结果的列类型?我阅读了psql文档,但我认为它不支持。理想情况下,我可以得到以下内容:

Is there a way to easily get the column types of a query result? I read the psql documentation, but I don't think it supports that. Ideally, I'd be able to get something like:

 columna : text | columnb : integer
----------------+-------------------
 oh hai         |                42

有没有一种方法可以获取这些信息而无需进行编码?

Is there a way I can get this information without coding something up?

推荐答案

除非您为示例编写存储过程,否则我认为您无法完全打印出示例中的内容。

I don't think you can print exactly what you have in the sample, unless you write a stored procedure for it.

一种方法(两个选择):

One way to do it (two "selects"):


  1. 创建表my_table作为select ...

  2. \d my_table

  3. 从my_table中选择*

  1. create table my_table as select ...
  2. \d my_table
  3. select * from my_table

这篇关于显示查询结果列类型(PostgreSQL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆