Command Line Tool: REPL

GreptimeDB has a simple REPL (“Read-Evaluate-Print-Loop”) command line tool for reading or writing data.

When running the new cli, you can specify the gRPC address of the GreptimeDB server you want to connect to:

shell

  1. ./greptime cli attach --grpc-addr=0.0.0.0:4001

Wait for the REPL’s prompt to come up:

txt

  1. Ready for commands. (Hint: try 'help')
  2. >

You can type in the “help” command to see some useful tips:

txt

  1. > help
  2. Available commands (case insensitive):
  3. - 'help': print this help
  4. - 'exit' or 'quit': exit the REPL
  5. - 'use <your database name>': switch to another database/schema context
  6. - Other typed-in texts will be treated as SQL statements.
  7. You can enter new lines while typing; remember to end it with ';'.

REPL provides “hints” based on your historical inputs. You can use the “tab” key to complete your inputs when some suggestions pop up — a handy feature powered by RustyLine.

To quickly familiarize yourself with GreptimeDB, try below examples:

  • To create or use a database (note: the database name is the current one in-use):

txt

  1. > create database foo;
  2. Affected Rows: 1
  3. Cost 21 ms
  4. > show databases;
  5. +---------+
  6. | Schemas |
  7. +---------+
  8. | foo |
  9. | public |
  10. +---------+
  11. Total Rows: 2
  12. Cost 8 ms
  13. > use foo;
  14. Total Rows: 0
  15. Cost 4 ms
  16. Using foo
  17. [foo] >
  • To create a table. REPL supports multi-line input (remember to end your input with a semicolon to make it a valid SQL statement):

txt

  1. [foo] > create table t(
  2. x STRING,
  3. ts TIMESTAMP TIME INDEX);
  4. Affected Rows: 0
  5. Cost 12 ms
  • To insert or select data:

txt

  1. [foo] > insert into t(x, ts) values('hello', 1);
  2. Affected Rows: 1
  3. Cost 5 ms
  4. [foo] > insert into t(x, ts) values('world', 2);
  5. Affected Rows: 1
  6. Cost 5 ms
  7. [foo] > select * from t;
  8. +-------+-------------------------+
  9. | x | ts |
  10. +-------+-------------------------+
  11. | hello | 1970-01-01T00:00:00.001 |
  12. | world | 1970-01-01T00:00:00.002 |
  13. +-------+-------------------------+
  14. Total Rows: 2
  15. Cost 17 ms