bayeslite icon indicating copy to clipboard operation
bayeslite copied to clipboard

query parameters for names, not just values

Open riastradh-probcomp opened this issue 9 years ago • 5 comments

We have far too much

qcn = bql_quote_name(column_name)
cursor = bdb.execute('ESTIMATE ... %s ... FROM t' % (qcn,))

throughout the tree. We have a mechanism for query parameters to pass in values, but no mechanism for query parameters to specify the names of tables, columns, &c.

riastradh-probcomp avatar Sep 16 '15 22:09 riastradh-probcomp

Candidate syntax:

ESTIMATE @column_0, @column_1 FROM @table WHERE @column_1 = :foobar

Here @column_0, @column_1, and @table specify query parameters for names, and :foobar specifies a query parameter for a value.

riastradh-probcomp avatar Sep 16 '15 22:09 riastradh-probcomp

Agree with the candidate syntax, how hard is the implementation?

fsaad avatar Sep 16 '15 22:09 fsaad

Not sure offhand. Teaching the scanner and parser should be easy. Teaching bdb.execute to distribute parameters appropriately may be more complicated -- that's all in bql.py and compiler.py.

riastradh-probcomp avatar Sep 16 '15 22:09 riastradh-probcomp

Should we also be solving the problem of substituting zero or more comma separated identifiers in certain places, like

ESTIMATE @column_0, @column_1 FROM @table WHERE @column_1 = :foobar

where the number of columns isn't known a priori? How about where the structure of the predicate isn't known either?

Do we really want a string substitution language, or do we want a linq-style query builder:

bdb.table("TableName").estimate("column0","column1").where(column="foobar").execute()

tibbetts avatar Sep 17 '15 04:09 tibbetts

I was thinking of @*columns for that yesterday.

As for query builder combinators vs query parameter notation, I don't know. Query combinators will require a lot more work to do well, and while they're more composable in one specific sense, it's much clumsier to write queries with them.

riastradh-probcomp avatar Sep 17 '15 16:09 riastradh-probcomp