gpt4 book ai didi

postgresql - 如何在 postgresql 中创建和存储对象数组

转载 作者:行者123 更新时间:2023-11-29 12:28:57 25 4
gpt4 key购买 nike

在 postgresql 中允许数组类型或整数和文本。但是我需要创建对象数组。我该怎么做。

myarray text[];   //for text ['a','b','c']
myarray integer[]; //for integer[1,2,3]

我需要像下面这样创建数组

[{'dsad':1},{'sdsad':34.6},{'sdsad':23}] 

我不想使用 JSON 类型。使用数组类型我需要存储对象数组。

最佳答案

如果您运行的是 Postgres 9.2+,则可以使用 JSON 类型。

例如,我们可以做

create table jsontest (id serial primary key, data json);
insert into jsontest (data) values ('[{"dsad":1},{"sdsad":34.6},{"sdsad":23}]');

并查询数据

select data->1 from jsontest;
{"sdsad":34.6}

关于postgresql - 如何在 postgresql 中创建和存储对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20095475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com