Skip to content

Instantly share code, notes, and snippets.

@mhausenblas
Created May 24, 2016 09:31
Show Gist options
  • Save mhausenblas/0723a83867dccdebabd7898847126e61 to your computer and use it in GitHub Desktop.
Save mhausenblas/0723a83867dccdebabd7898847126e61 to your computer and use it in GitHub Desktop.
CockroachDB: create table, insert data and query it
core@ip-10-0-7-99 ~ $ docker run -it cockroachdb/cockroach:beta-20160512 sql --host=10.0.7.99 --port=12504 --user=maxroach
# Welcome to the cockroach SQL interface.
# All statements must be terminated by a semicolon.
# To exit: CTRL + D.
[email protected]:12504> SET DATABASE = bank;
[email protected]:12504> CREATE TABLE accounts (id INT PRIMARY KEY, balance INT);
[email protected]:12504> INSERT INTO accounts (id, balance) VALUES (1, 1000), (2, 250);
INSERT 2
[email protected]:12504> INSERT INTO accounts (id, balance) VALUES (3, 10), (4, 670);
INSERT 2
[email protected]:12504> SELECT id, balance FROM accounts;
+----+---------+
| id | balance |
+----+---------+
| 1 | 1000 |
| 2 | 250 |
| 3 | 10 |
| 4 | 670 |
+----+---------+
[email protected]:12504> SELECT SUM(balance) FROM accounts;
+--------------+
| SUM(balance) |
+--------------+
| 1930 |
+--------------+
[email protected]:12504> SELECT AVG(balance) FROM accounts;
+----------------------+
| AVG(balance) |
+----------------------+
| 482.5000000000000000 |
+----------------------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment