gpt4 book ai didi

database - YugaByte DB SQL API 是否支持数组类型

转载 作者:搜寻专家 更新时间:2023-10-30 23:25:54 27 4
gpt4 key购买 nike

YugaByte 的 SQL 是否支持 PostgreSQL 中存在的数组数据类型(如 https://www.postgresql.org/docs/9.1/arrays.html)?

最佳答案

是的,YugabyteDB 确实支持 PostgreSQL 数组类型。不幸的是,它还没有记录 ( https://github.com/yugabyte/yugabyte-db/issues/1798 )。我将很快将其添加到 Data types 中的 YugabyteDB 文档中部分。

以下是一些示例,已在我们的最新版本中进行测试:

01:39 $ ./bin/ysqlsh
ysqlsh (11.2-YB-2.0.0.0-b0)
Type "help" for help.

yugabyte=# select array_append(ARRAY[1,2], 3);
array_append
--------------
{1,2,3}
(1 row)

yugabyte=# select array_position(ARRAY['sun','mon','tue','wed','thu','fri','sat'], 'mon');
array_position
----------------
2
(1 row)

yugabyte=# CREATE TABLE sal_emp (
yugabyte(# name text,
yugabyte(# pay_by_quarter integer[],
yugabyte(# schedule text[][]
yugabyte(# );
CREATE TABLE

yugabyte=# \d sal_emp;
Table "public.sal_emp"
Column | Type | Collation | Nullable | Default
----------------+-----------+-----------+----------+---------
name | text | | |
pay_by_quarter | integer[] | | |
schedule | text[] | | |

yugabyte=# INSERT INTO sal_emp
yugabyte-# VALUES ('Bill',
yugabyte(# '{10000, 10000, 10000, 10000}',
yugabyte(# '{{"meeting", "lunch"}, {"training", "presentation"}}');
INSERT 0 1
yugabyte=#
yugabyte=# INSERT INTO sal_emp
yugabyte-# VALUES ('Carol',
yugabyte(# '{20000, 25000, 25000, 25000}',
yugabyte(# '{{"breakfast", "consulting"}, {"meeting", "lunch"}}');
INSERT 0 1
yugabyte=# select * from sal_emp;
name | pay_by_quarter | schedule
-------+---------------------------+-------------------------------------------
Carol | {20000,25000,25000,25000} | {{breakfast,consulting},{meeting,lunch}}
Bill | {10000,10000,10000,10000} | {{meeting,lunch},{training,presentation}}
(2 rows)

关于database - YugaByte DB SQL API 是否支持数组类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57993866/

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