Showcasing the array
SQL data type.
A dataset of "observations" is used to explore the array
data type.
Follow these instructions to explore arrays in Postgres.
- Start the Postgres server
- Use whatever method you prefer: HomeBrew, Docker, etc. Depending on how you install it, the username and database
name will differ so take care to adjust the
psql
commands accordingly.
- Use whatever method you prefer: HomeBrew, Docker, etc. Depending on how you install it, the username and database
name will differ so take care to adjust the
- Apply the schema:
-
psql -f observations-schema.ddl
-
- Insert test data:
-
psql -f observations-data.sql
-
- Try out the queries in
observations-explore.sql
and learn about SQL arrays!- For example, execute the
observations-ad-hoc-query.sh
with the following command. -
./observations-ad-hoc-query.sh
- It will output the following.
-
format | array_length ------------------------------+-------------- "groundbreaking observation" | 1 "underwhelming observation" | 2 (2 rows)
- For example, execute the