【问题标题】:Does YugaByte DB’s YSQL API support array typesYugaByte DB SQL API 是否支持数组类型
【发布时间】:2019-09-18 13:25:12
【问题描述】:

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

【问题讨论】:

    标签: database distributed-database yugabyte-db


    【解决方案1】:

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

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

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-27
      • 1970-01-01
      相关资源
      最近更新 更多