From: Bjorn B. <bri...@cs...> - 2006-07-12 22:21:48
|
On Jul 12, 2006, at 3:02 PM, Matthias Radestock wrote: > > How can I insert rows into a table with some column values coming =20 > from a > query and the rest being set to their defaults? > > insertQuery generates SQL of the form > > INSERT INTO table (SELECT ...) > > This doesn't allow default values to be specified because a) the =20 > SELECT > must produce as many columns as there are in the table, b) it is =20 > illegal > to write something like 'SELECT DEFAULT,..'. > > By contrast > > INSERT INTO table(column,...) (SELECT ...) > > will give default values to all the columns that do not appear in the > column list. However, from my experimenting and looking at the code it > appears that there is currently no way to construct such a query. > > Would it be possible to add this? I suspect one difficulty might be > expressing the record typing constraints required to make this =20 > operation > safe. HaskellDB's support for using default values is not very good. I =20 think that we would need a subtyping relation on records to implement =20= this properly. You will find that there are more things missing, like left joins. I =20 usually just fake whatever is missing using Haskell code, but that is =20= of course less efficient. I am starting to think that HaskellDB needs a serious overhaul to fix =20= problems like this, and address back-end incompatibilities. I just =20 need to find the time to do it. /Bj=F6rn |