{
  "schema_version": 2,
  "id": "integrate/redis-adbc-driver/quick-start",
  "title": "Query Redis with SQL and Arrow",
  "url": "https://redis.io/docs/latest/integrate/redis-adbc-driver/quick-start/",
  "summary": "Create a table, load Arrow data, and query Redis with SQL from Python.",
  "tags": [
    "docs",
    "integrate",
    "oss",
    "rs",
    "rc"
  ],
  "last_updated": "2026-11-17T10:18:45Z",
  "page_type": "content",
  "content_hash": "86733f2e1628ae5dd25b85e143a958c7e4cdb56cea6913ff54e3b66783eb3e39",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "This page shows how to create a SQL table in Redis, load Arrow data into it,\nquery it, and read the results into pandas and Polars."
    },
    {
      "id": "before-you-start",
      "title": "Before you start",
      "role": "content",
      "text": "1. [Install the driver and check your connection](https://redis.io/docs/latest/integrate/redis-adbc-driver/install).\n   Keep `REDIS_URI` set in your environment.\n\n1. Install pandas and Polars for the last step:\n\n    [code example]\n\nThe examples create a table named `orders` in the `public` schema. If your\ndatabase already has a table with that name, the first step replaces it."
    },
    {
      "id": "create-a-table-and-insert-rows",
      "title": "Create a table and insert rows",
      "role": "content",
      "text": "Create a file named `create_table.py` with the following text:\n\n[code example]\n\nRun it using the command shown below:\n\n[code example]\n\nThe driver creates a [Query Engine index](https://redis.io/docs/latest/develop/ai/search-and-query)\nfor the table and stores each row as a\nRedis [hash](https://redis.io/docs/latest/develop/data-types/hashes). Every statement commits on its own."
    },
    {
      "id": "load-an-arrow-table",
      "title": "Load an Arrow table",
      "role": "content",
      "text": "To load many rows, pass an Arrow table to `adbc_ingest`. Create a file named\n`ingest.py`:\n\n[code example]\n\nRun it:\n\n[code example]\n\nThe `mode` argument controls how the load treats the table:\n\n| Mode | Behavior |\n| :-- | :-- |\n| `append` | Add the rows to an existing table. |\n| `create` | Create the table from the Arrow schema, then load the rows. |\n| `create_append` | Create the table if it doesn't exist, then add the rows. |\n| `replace` | Replace the table's rows with the new data. |"
    },
    {
      "id": "query-the-table",
      "title": "Query the table",
      "role": "content",
      "text": "Create a file named `query.py`:\n\n[code example]\n\nRun it. The results come back as Arrow tables:\n\n[code example]\n\n[code example]"
    },
    {
      "id": "read-the-results-into-pandas-and-polars",
      "title": "Read the results into pandas and Polars",
      "role": "content",
      "text": "Because the driver returns Arrow data, DataFrame libraries can read it without\nextra conversion code. Create a file named `dataframes.py`:\n\n[code example]\n\nRun it:\n\n[code example]\n\n[code example]\n\nThe query casts the sum to `NUMERIC(12,2)`. Without the cast, the driver\nreturns a 256-bit decimal whose precision depends on the data, and some\nreaders, including Polars, can't import it."
    },
    {
      "id": "clean-up",
      "title": "Clean up",
      "role": "content",
      "text": "To remove the table, run:\n\n[code example]\n\nThe table stops existing immediately, and queries against it fail. The driver\nreleases the table's rows and index in the background rather than during the\nstatement, so Redis memory use doesn't drop right away. The project's\n`redis-adbc sweep` tool reclaims leftover rows. See\n[Sweep leftover rows](https://redis.github.io/redis-adbc-driver/docs/driver-reference/#sweep-leftover-rows)\nin the driver reference."
    },
    {
      "id": "next-steps",
      "title": "Next steps",
      "role": "content",
      "text": "- Read the [driver reference](https://redis.github.io/redis-adbc-driver/docs/driver-reference/)\n  for the supported SQL, connection options, and ACL requirements.\n- Connect other [data tools](https://redis.io/docs/latest/integrate/redis-adbc-driver#data-tools)."
    }
  ],
  "examples": [
    {
      "id": "before-you-start-ex0",
      "language": "bash",
      "code": "python -m pip install pandas polars",
      "section_id": "before-you-start"
    },
    {
      "id": "create-a-table-and-insert-rows-ex0",
      "language": "python",
      "code": "import os\n\nfrom adbc_driver_redis import dbapi\n\nwith dbapi.connect(os.environ[\"REDIS_URI\"]) as conn:\n    with conn.cursor() as cur:\n        cur.execute(\"DROP TABLE IF EXISTS orders\")\n        cur.execute(\n            \"CREATE TABLE orders (\"\n            \"order_id INT, country TEXT, product TEXT, \"\n            \"quantity INT, unit_price NUMERIC(10,2))\"\n        )\n        cur.execute(\n            \"INSERT INTO orders VALUES \"\n            \"(1, 'JPN', 'keyboard', 2, 49.90), \"\n            \"(2, 'USA', 'monitor', 1, 189.00), \"\n            \"(3, 'JPN', 'monitor', 3, 189.00)\"\n        )",
      "section_id": "create-a-table-and-insert-rows"
    },
    {
      "id": "create-a-table-and-insert-rows-ex1",
      "language": "bash",
      "code": "python create_table.py",
      "section_id": "create-a-table-and-insert-rows"
    },
    {
      "id": "load-an-arrow-table-ex0",
      "language": "python",
      "code": "import os\n\nimport pyarrow as pa\nfrom adbc_driver_redis import dbapi\n\nmore_orders = pa.table(\n    {\n        \"order_id\": pa.array([4, 5], pa.int32()),\n        \"country\": [\"USA\", \"DEU\"],\n        \"product\": [\"keyboard\", \"mouse\"],\n        \"quantity\": pa.array([5, 10], pa.int32()),\n        \"unit_price\": pa.array([49.90, 12.50]).cast(pa.decimal128(10, 2)),\n    }\n)\n\nwith dbapi.connect(os.environ[\"REDIS_URI\"]) as conn:\n    with conn.cursor() as cur:\n        cur.adbc_ingest(\"orders\", more_orders, mode=\"append\")",
      "section_id": "load-an-arrow-table"
    },
    {
      "id": "load-an-arrow-table-ex1",
      "language": "bash",
      "code": "python ingest.py",
      "section_id": "load-an-arrow-table"
    },
    {
      "id": "query-the-table-ex0",
      "language": "python",
      "code": "import os\n\nfrom adbc_driver_redis import dbapi\n\nwith dbapi.connect(os.environ[\"REDIS_URI\"]) as conn:\n    with conn.cursor() as cur:\n        cur.execute(\"SELECT * FROM orders ORDER BY order_id\")\n        print(cur.fetch_arrow_table())\n\n        cur.execute(\n            \"SELECT country, COUNT(*) AS orders, SUM(quantity) AS units \"\n            \"FROM orders GROUP BY country ORDER BY units DESC\"\n        )\n        print(cur.fetch_arrow_table())",
      "section_id": "query-the-table"
    },
    {
      "id": "query-the-table-ex1",
      "language": "bash",
      "code": "python query.py",
      "section_id": "query-the-table"
    },
    {
      "id": "query-the-table-ex2",
      "language": "text",
      "code": "pyarrow.Table\norder_id: int32\ncountry: string\nproduct: string\nquantity: int32\nunit_price: decimal128(10, 2)\n----\norder_id: [[1,2,3,4,5]]\ncountry: [[\"JPN\",\"USA\",\"JPN\",\"USA\",\"DEU\"]]\nproduct: [[\"keyboard\",\"monitor\",\"monitor\",\"keyboard\",\"mouse\"]]\nquantity: [[2,1,3,5,10]]\nunit_price: [[49.90,189.00,189.00,49.90,12.50]]\npyarrow.Table\ncountry: string\norders: int64\nunits: int64\n----\ncountry: [[\"DEU\",\"USA\",\"JPN\"]]\norders: [[1,2,2]]\nunits: [[10,6,5]]",
      "section_id": "query-the-table"
    },
    {
      "id": "read-the-results-into-pandas-and-polars-ex0",
      "language": "python",
      "code": "import os\n\nimport pandas as pd\nimport polars as pl\nfrom adbc_driver_redis import dbapi\n\nuri = os.environ[\"REDIS_URI\"]\nquery = (\n    \"SELECT country, \"\n    \"CAST(SUM(quantity * unit_price) AS NUMERIC(12,2)) AS revenue \"\n    \"FROM orders GROUP BY country ORDER BY revenue DESC\"\n)\n\nwith dbapi.connect(uri) as conn:\n    print(pd.read_sql(query, conn))\n\nprint(pl.read_database_uri(query, uri, engine=\"adbc\"))",
      "section_id": "read-the-results-into-pandas-and-polars"
    },
    {
      "id": "read-the-results-into-pandas-and-polars-ex1",
      "language": "bash",
      "code": "python dataframes.py",
      "section_id": "read-the-results-into-pandas-and-polars"
    },
    {
      "id": "read-the-results-into-pandas-and-polars-ex2",
      "language": "text",
      "code": "country revenue\n0     JPN  666.80\n1     USA  438.50\n2     DEU  125.00\nshape: (3, 2)\n┌─────────┬───────────────┐\n│ country ┆ revenue       │\n│ ---     ┆ ---           │\n│ str     ┆ decimal[12,2] │\n╞═════════╪═══════════════╡\n│ JPN     ┆ 666.80        │\n│ USA     ┆ 438.50        │\n│ DEU     ┆ 125.00        │\n└─────────┴───────────────┘",
      "section_id": "read-the-results-into-pandas-and-polars"
    },
    {
      "id": "clean-up-ex0",
      "language": "bash",
      "code": "python -c \"\nimport os\nfrom adbc_driver_redis import dbapi\nwith dbapi.connect(os.environ['REDIS_URI']) as conn, conn.cursor() as cur:\n    cur.execute('DROP TABLE orders')\n\"",
      "section_id": "clean-up"
    }
  ]
}
