OCaml Forge

Forum: open-discussion

Discussion Forums: open-discussion

Monitor Forum | Start New Thread Start New Thread
RE: What is the intent of the default values in table descriptions ? [ reply ]
By: Gabriel Scherer on 2013-02-21 07:03
I think generating Macaque descriptions from the table is a good idea (given that I don't plan to implement all the RDMBS features, so the DB will always be more featureful). For this a DEFAULT clause *without* the default value (left to the RDBMS) would be useful indeed. Would you care to try to propose a patch for that?

RE: What is the intent of the default values in table descriptions ? [ reply ]
By: Fabian Pijcke on 2013-02-21 02:47
Thanks for your answer, I will use the mailing list next time :-) I understand the reason of the presence of the DEFAULT clause.

My intent was to do the exact opposite of what you plan to do, i.e. generating the descriptions from the database, but this seems to be really hard as some default clauses may be really tricky, and the types also may be really hard to "parse". I think I will drop this idea, or insert "tags" where it is too hard to retrieve a good description of a table.

See you,


RE: What is the intent of the default values in table descriptions ? [ reply ]
By: Gabriel Scherer on 2013-02-20 22:38
Your question is fine, thank you. If you have further question, I'm more comfortable with using a mailing interface, and there is a macaque mailing-list ( https://lists.ocamlcore.org/cgi-bin/listinfo/macaque-discuss ) that I would encourage you to use.

The reason why I have added a Default value in Macaque directly (this was not in the initial release, but a feature added at an user request) is that the strict typing discipline that is central to Macaque's design makes it hard to simply rely on the database as you suggest.

To be able to statically type-check table uses, I need an OCaml representation of their type (and I trust this representation, or use the Check model to verify it). Macaque will make sure that insertion queries have the right type, and in particular have values all the columns that are present in (the static description of) the table, and forbid creation of partial rows with missing columns. So whether or not you used a DEFAULT value in the SQL table creation command, you need some way to inform Macaque that "it's ok type-wise to not give a value for this field". Macaque-side DEFAULT was just the most natural choice, but indeed I could have a flag that only says "HAS-DEFAULT" and relies on the database itself to store it. I'm not sure either approach is clearly much better than the other.

(One reason to have DEFAULT rather than HAS-DEFAULT was the idea that, maybe someday, we would provide a way to create a table directly from the Macaque description, instead of asking users to both define the table in the RDBMS and describe it on Macaque's side. Of course, such a feature would not be realistic currently as Macaque's table description language is much poorer than what users want to say (foreign key constraints, etc.), and I'm not sure it will ever exist or is a good idea in the long run).

What is the intent of the default values in table descriptions ? [ reply ]
By: Fabian Pijcke on 2013-02-20 20:43

Sorry if my question seems idiot or even hostile (which is not my intention at all).

When describing a table using <:table< ... >>, you allow one to specify default values for the fields. I would like to know what is the intent of this feature ...

If it is to allow the user to specify a different default value than the database default value, then I have nothing to add, except I think this is a strange idea, but why not :p

If it is because you need to pass full tuples (for example in <:insert< my_table := { id = my_table?id; ... } >> statement), which I think is the reason, but I may be wrong, then isn't it possible to use the DEFAULT keyword of PostGreSQL ? (for example, the following statement is valid in PgSQL: INSERT INTO my_table VALUES (DEFAULT, 1, 'Hello'); ) and therefore abandon the DEFAULT clause, which is IMHO the matter of the RDBMS and not of macaque (for the same reason, you let the optimizer handle large queries, and do not try to optimize yourself this query).

To be more clear, I think that if the only usage of those default values is for an INSERT statement, it would be better for the user to use the actual syntax for the <:insert< ... >>, but without having to give that information to the <:table<< ... >> value.

Sorry for my approximative English, I sincerely hope you don't misunderstand me; this is a peaceful message :-)