【问题标题】:How to know the type of a value returned by a Redshift query?如何知道 Redshift 查询返回的值的类型?
【发布时间】:2020-07-01 20:20:46
【问题描述】:

在 PostgreSQL 中,您可以使用 SELECT 语句中的函数pg_typeof() 来获取 SQL 查询返回值的数据类型。

尽管有 Redshift 的 SQL 血统,但该函数在 Redshift 中不存在。

我想这样做:

SELECT pg_typeof(0.25::numeric(5,2)) ;

然后得到:

numeric(5,2)

如何获取 SQL 查询返回的值的数据类型? 这是为了帮助我对我的 ETL 开发进行单元测试。

【问题讨论】:

  • 我认为无法检查查询中的列类型。

标签: sql amazon-redshift


【解决方案1】:

不确定是否可以在您的用例中使用,但我使用此查询来获取 Redshift 中的类型

SELECT distinct 
        t.relname as table,
        a.attname as column,
        pg_catalog.format_type(a.atttypid, a.atttypmod) as type
FROM pg_attribute a
    JOIN pg_class t on a.attrelid = t.oid
    JOIN pg_namespace s on t.relnamespace = s.oid
WHERE a.attnum > 0 
    AND NOT a.attisdropped
    AND LENGTH(a.attname) > 1
    AND s.nspname in ({{schemas}})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-17
    • 2020-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多