bayeslite
bayeslite copied to clipboard
query parameters for names, not just values
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.
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.
Agree with the candidate syntax, how hard is the implementation?
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.
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()
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.