1

Does YugaByte’s SQL support array data type present in PostgreSQL (like https://www.postgresql.org/docs/9.1/arrays.html)?

1 Answers1

2

Yes, YugabyteDB does support the PostgreSQL array types. Unfortunately, it's not documented yet (https://github.com/yugabyte/yugabyte-db/issues/1798). I'll be adding that soon to the YugabyteDB docs in the Data types section.

Here are some examples, tested in our latest release:

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)
Steve Bang
  • 21
  • 2