YugaByte DB 的 YSQL API 是否支持数组类型?



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

是的,YugabyteDB确实支持PostgreSQL数组类型。不幸的是,它还没有记录在案(https://github.com/yugabyte/yugabyte-db/issues/1798(。我将很快将其添加到 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)

相关内容

  • 没有找到相关文章

最新更新