【问题标题】:How to access individual elements of user defined data types?如何访问用户定义数据类型的各个元素?
【发布时间】:2022-01-15 13:15:11
【问题描述】:

这是一个 Postgres SQL 问题。

我有一个用户定义的数据类型如下。

create type my_type as (name varchar(100), credit_points double precision)

我有一个使用上述类型作为列数据类型的表,如下所示。

create table tab1 (
    id serial,
    name_credit my_type
)

我可以使用下面的插入语句将值插入到这个表中。

insert into tab1 (name_credit) values(('santhosh', 101.75)::my_type)

现在,我想访问下表。

select * from tab1 where name_credit[2] between 100.0 and 110.0

select * from tab1 where name_credit.credit_points between 100.0 and 110.0

但这两种方法都不适合我。请问有什么想法吗?

【问题讨论】:

    标签: postgresql


    【解决方案1】:

    将列名放入()

    SELECT *
           FROM tab1
           WHERE (name_credit).credit_points BETWEEN 100.0
                                                     AND 110.0;
    

    更多详情请见"8.16.3. Accessing Composite Types"

    【讨论】:

      猜你喜欢
      • 2019-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-31
      • 1970-01-01
      • 2019-02-07
      • 2017-02-19
      • 2011-03-03
      相关资源
      最近更新 更多