YugaByte 的 SQL 是否支持 PostgreSQL 中存在的数组数据类型(如https://www.postgresql.org/docs/9.1/arrays.html)?
问问题
83 次
1 回答
2
是的,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)
于 2019-09-19T17:23:00.893 回答