databasetime-seriesquestdb

Polars query to QuestDB results in "query is not allowed here"


What's the fastest way to query data?

Typically I would use polars to just read directly with zero copy through their ConnectorX engine

uri = "postgresql://username:password@server:port/database"
query = "SELECT * FROM foo"

pl.read_database_uri(query=query, uri=uri)

But this isn't working "db error: db error: ERROR: query is not allowed here"

It this because QuestDB doesn't support Arrow engines?


Solution

  • A colleage just told me you can also pretend to be redshift, which has similar constraints

    QUESTDB_URI = "redshift://admin:quest@localhost:8812/qdb"
    QUERY = "SELECT * FROM tables() LIMIT 5;"
    
    df = pl.read_database_uri(query=QUERY, uri=QUESTDB_URI)
    print("Received DataFrame:")
    print(df)
    

    Or you can still use the postgresql connection string, but selection cursor or simple as protocols

    import polars as pl
    
    QUESTDB_URI = "postgresql://admin:quest@localhost:8812/qdb"
    QUERY = "SELECT * FROM tables() LIMIT 5;"
    PROTOCOL = "cursor" # works with 'simple' too
    
    df = pl.read_database_uri(query=QUERY, uri=QUESTDB_URI, protocol=PROTOCOL)
    print("Received DataFrame