Skip to content

Named query parameters are sensitive to position when specifying kwargs #85

@slwu89

Description

@slwu89

Hi, I noticed that when using Var, and specifying the query parameter values as keyword arguments in DBInterface.execute, it is sensitive to the order that they are given in (i.e. they must match the order that they appear in the query). This seems strange to me given that we are specifying their "names" anyway, is there a way to fix this? On [cf6cc811] FunSQL v0.15.0.

using DataFrames
using DuckDB
using FunSQL:
    FunSQL, Agg, Append, As, Asc, Bind, CrossJoin, Define, Desc, Fun, From,
    Get, Group, Highlight, Iterate, Join, LeftJoin, Limit, Lit, Order,
    Partition, Select, Sort, Var, Where, With, WithExternal, render

con = DBInterface.connect(DuckDB.DB, ":memory:")
catalog = FunSQL.reflect(con)

DBInterface.execute(con, """
    CREATE TABLE tab (
        name TEXT,
        val NUMERIC
    );
""")

DBInterface.execute(con, """
    INSERT INTO tab VALUES
    ('a', 5),
    ('b', 6),
    ('c', 5),
    ('a', 3),
    ('b', 4),
    ('c', 2);
""")

q = From(:tab) |> Where(Fun.or(Get.name .== Var.NAME, Get.val .== Var.VAL)) |> Select(:name, :val)

# works
DataFrame(DBInterface.execute(con, render(catalog, q); NAME="a", VAL=5))

# this is unexpected
DataFrame(DBInterface.execute(con, render(catalog, q); VAL=5, NAME="a"))

DBInterface.close!(con)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions