LinuxCommandLibrary

rsql

Query SQL databases

TLDR

Enter interactive mode

$ rsql
copy

Connect to a database (e.g. PostgreSQL)
$ rsql --url ["postgresql://user:pass@localhost/mydb"]
copy

Connect to a PostgreSQL database with SSL
$ rsql --url ["postgresql://user:pass@localhost/db?sslmode=require"]
copy

Connect to a MySQL database with a specified charset
$ rsql --url ["mysql://user:pass@localhost/db?charset=utf8mb4"]
copy

Run a query and exit
$ rsql --url ["sqlite://database.db"] -- "SELECT * FROM users LIMIT 10"
copy

Set default format
$ rsql --url ["sqlite://db.sqlite"] --format json
copy

Connect to file and use custom line separator
$ rsql --url ["delimited://data.txt?separator=|&has_header=true"]
copy

SYNOPSIS

rsql [OPTIONS] [SQL_QUERY]

PARAMETERS

-h, --host
    Specifies the Redis server hostname or IP address. Default is 127.0.0.1.

-p, --port
    Sets the Redis server port number. Default is 6379.

-a, --password
    Provides the password to authenticate with the Redis server.

-n, --db
    Selects the Redis logical database number. Default is 0.

-f, --file
    Executes SQL commands from the specified file instead of stdin.

--csv
    Outputs results in CSV format.

--json
    Outputs results in JSON format.

--no-header
    Suppresses the header row in table output.

--help
    Displays help information and exits.

--version
    Shows the version information and exits.

DESCRIPTION

The rsql command provides a powerful SQL-like interface for interacting with Redis databases. It allows users familiar with traditional relational database query languages (like SQL) to query and manipulate data stored in Redis, abstracting away the native Redis commands. This tool bridges the gap between the NoSQL nature of Redis and the comfort of SQL for many developers and administrators. It translates SQL queries into appropriate Redis commands, executes them, and formats the results in a readable manner, often as tables.

While not a standard Linux utility in the same vein as `ls` or `grep`, rsql is a specialized client designed to simplify Redis operations, making it accessible to a wider audience without needing to master Redis's specific command set.

CAVEATS

rsql is a third-party client and not part of the standard Redis distribution or a default Linux installation. Its availability depends on whether it has been specifically installed on the system.

While it provides a SQL-like interface, it does not support the full breadth of SQL features, as Redis is a NoSQL database with a different data model. Complex joins, advanced aggregations, or transactional integrity mechanisms common in relational databases might be limited or unsupported. Users should be aware of the specific SQL subset implemented by their version of rsql.

HISTORY

The rsql tool emerged as a community-driven effort to enhance Redis's accessibility, particularly for users accustomed to relational databases. Its development was motivated by the desire to allow data analysts, developers, and administrators to leverage their existing SQL knowledge to interact with Redis, thereby reducing the learning curve associated with Redis-specific commands. It acts as an abstraction layer, translating familiar SQL queries into native Redis operations, reflecting a common trend in the NoSQL ecosystem to provide SQL-compatible interfaces.

SEE ALSO

redis-cli(1), mysql(1), psql(1), sqlite3(1)

Copied to clipboard