Skip to content

Instantly share code, notes, and snippets.

@ykessler
Created September 25, 2018 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ykessler/60123a62491bc5e85531e95cc9338f16 to your computer and use it in GitHub Desktop.
Save ykessler/60123a62491bc5e85531e95cc9338f16 to your computer and use it in GitHub Desktop.
Examples of two types of syntax for postres arrays.
-- Examples of two types of syntax for postres arrays.
-- EXAMPLE 1 AND 2 ARE THE SAME:
-- EXAMPLE 1 - ARRAY SYNTAX:
INSERT INTO sample_table
VALUES (
ARRAY[10000, 20000, 30000, 40000],
ARRAY['red', 'blue', 'green'],
ARRAY[['meeting', 'lunch'], ['training', 'presentation']]
);
-- EXAMPLE 2 - CURLY SYNTAX:
INSERT INTO sample_table
VALUES (
'{10000, 20000, 30000, 40000}',
'{"red", "blue", "green"}',
'{{"meeting", "lunch"}, {"training", "presentation"}}'
);
-- Multidimensional arrays must have matching extents for each dimension. A mismatch causes an error, for example:
INSERT INTO sample_table
VALUES (
'{10000, 10000, 10000, 10000}',
'{{"meeting", "lunch"}, {"meeting"}}'
);
ERROR: multidimensional arrays must have array expressions with matching dimensions
-- SEE ALSO:
-- https://www.postgresql.org/docs/9.1/static/arrays.html
-- http://www.postgresqltutorial.com/postgresql-array/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment