Skip to content
Prev 1343 / 1559 Next

SQL generics

Hi Hadley,

The sqlQuoteString() and sqlQuoteIdentifer() generics are useful.
More generally speaking I like the idea of providing utilities that
make it easier to generate SQL, and even better if those utilities
help generate SQL that will automagically adapt to the current back-end.

Because of the sql prefix my understanding is that the generics below
(sqlCreateTable(), etc...) only generate strings containing valid SQL
but that they actually don't talk to the db. I understand that you
need the 'conn' argument for dispatch but it might be a little bit
confusing.

Are you also considering to provide dbCreateTable(), dbDropTable(),
dbInsertInto(), dbUpdate(), and dbDeleteFrom() generics?

Do we really need the 2 sets? If not, which one is most useful?
Alternatively the 2nd set could have a 'return.SQL.only' arg (FALSE
by default) so the user/developer has a way to know what SQL
is sent to the db (can be useful for learning/debugging, or for
"retouching" the query before sending).

If it was possible to use only high-level back-end agnostic commands
like this in our R code when talking to a db, then it would be easy
to support multiple back ends. Sounds like a noble goal in theory but
it might be hard to achieve. As you noticed the grammar of the SELECT
statement is complicated and complex statements can require a lot of
back-end specific tweaking in order to perform efficiently.

Thanks,
H.
On 10/22/2013 01:56 PM, Hadley Wickham wrote: