PostgreSQL中的多种数据类型数组 [英] Multiple data types array in PostgreSQL

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

问题描述

很抱歉,如果它是重复的,尽管我在任何地方都找不到确切的答案:

有没有一种方法可以在 postgreSQL 其中包含多种数据类型?



我有一个类型为 text [] 的列(文本类型的数组);尽管我想在此数组中插入三个 text 条目,然后插入第四个条目,类型为 integer 。 / p>

有办法吗?如果是,怎么办?

解决方案

我不相信有一种方法可以声明具有多个类型的数组。但是,我认为您可以使用复合类型来完成您要执行的操作,例如

 创建类型my_item为(
field_1文本,
field_2文本,
field_3 text,
field_4 number
);

然后您可以将其用作表的列类型,甚至可以声明 my_item [] 如果适合您的需求。


I'm sorry if this is a duplicate, although I couldn't find an exact answer for this anywhere:
Is there a way to create an array in postgreSQL which contains multiple data types?

I have an column of type text[] (array of type text); although I'd like to insert into this array three text entries and then a fourth entry, from type integer.

Is there a way to do so? If so, how?

解决方案

I don't believe there's a way to declare an array with multiple types; however, I think you can accomplish what you are trying to do with a composite type, e.g.,

create type my_item as (
    field_1        text,
    field_2        text,
    field_3        text,
    field_4        number
);

You could then use this as the column type for your table or even declare a column of arrays of my_item[] if that fits your need.

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

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