在postgres中选择字段的数据类型 [英] Select datatype of the field in postgres

查看:68
本文介绍了在postgres中选择字段的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从Postgres中的表中获取特定字段的数据类型?
例如
我有下表,
student_details(
stu_id整数,
stu_name varchar(30),
join_date时间戳
) ;

How do I get datatype of specific field from table in postgres ? For example I have the following table, student_details ( stu_id integer, stu_name varchar(30 ), joined_date timestamp );

在此使用字段名称/或任何其他方式,我需要获取特定字段的数据类型。有可能吗?

In this using the field name / or any other way, I need to get the datatype of the specific field. Is there any possibility ?

推荐答案

您可以从 information_schema (此处引用了8.4个文档,但这不是新功能):

You can get data types from the information_schema (8.4 docs referenced here, but this is not a new feature):

=# select column_name, data_type from information_schema.columns
-# where table_name = 'config';
    column_name     | data_type 
--------------------+-----------
 id                 | integer
 default_printer_id | integer
 master_host_enable | boolean
(3 rows)

这篇关于在postgres中选择字段的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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