PostgreSQL/Array/Array Column

Материал из SQL эксперт
Перейти к: навигация, поиск

Creating a table with a multidimensional array column

   <source lang="sql">

postgres=# -- Creating a table with a multidimensional array column postgres=# postgres=# CREATE TABLE authors (id integer,titles text[][]); CREATE TABLE postgres=# postgres=# drop table authors; DROP TABLE postgres=#

      </source>
   
  


Creating a table with an array column

   <source lang="sql">

postgres=# -- Creating a table with an array column postgres=# postgres=# CREATE TABLE books (employee_id integer, books text[]); CREATE TABLE postgres=# postgres=# postgres=# drop table books; DROP TABLE postgres=#

      </source>
   
  


Integer array and text array

   <source lang="sql">

postgres=# -- Declaration of Array Types postgres=# postgres=# CREATE TABLE sal_emp ( postgres(# name text, postgres(# pay_by_quarter integer[], postgres(# schedule text[][] postgres(# ); CREATE TABLE postgres=# INSERT INTO sal_emp postgres-# VALUES ("A", postgres(# "{10000, 10000, 10000, 10000}", postgres(# "{{"A", "B"}, {"C", "D"}}"); INSERT 0 1 postgres=# postgres=# INSERT INTO sal_emp postgres-# VALUES ("B", postgres(# "{20000, 25000, 25000, 25000}", postgres(# "{{"Z", "X"}, {"Y", "Q"}}"); INSERT 0 1 postgres=# postgres=# postgres=# SELECT * FROM sal_emp;

name |      pay_by_quarter       |   schedule

+---------------------------+---------------
A    | {10000,10000,10000,10000} | {{A,B},{C,D}}
B    | {20000,25000,25000,25000} | {{Z,X},{Y,Q}}

(2 rows) postgres=# postgres=# drop table sal_emp; DROP TABLE postgres=#

      </source>
   
  


Two dimentional array

   <source lang="sql">

postgres=# CREATE TABLE t ( postgres(# squares integer[3][3] postgres(# ); CREATE TABLE postgres=# postgres=# \d t;

       Table "public.t"
Column  |   Type    | Modifiers

+-----------+-----------
squares | integer[] |

postgres=# postgres=# drop table t; DROP TABLE postgres=#

      </source>