martinjw/dbschemareader

PostgreSQL: Cannot use functions as default value

Closed this issue · 2 comments

Hi. Thanks for the great project!

When creating a script for PostgreSQL setting the default value of a column to now() (or any other function) does result in invalid SQL. The reason for this is that the TableGenerator.WriteDefaultValue() method trims the braces.

I think a better approach would be to check whether the value starts with a parenthesis and only then remove the one at the end.
Another idea would be to just not remove parenthesis if the default value contains () or maybe a combination of the two. Manually adding every possible function seems like a very tedious and very inefficient approach.

A function that we're currently using and that is not in the list is i.e. uuid_generate_v4() and I'm sure there are a bazillion more possibilities.

There was probably a reason why we strip the parenthesis, but I can't remember what it was, and just not trying to convert them seems a better idea just now!