Created
September 25, 2018 14:18
-
-
Save ykessler/60123a62491bc5e85531e95cc9338f16 to your computer and use it in GitHub Desktop.
Examples of two types of syntax for postres arrays.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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