martinjw / dbschemareader

Read database metadata (from SqlServer/Oracle/MySql/SQLite/PostgreSql/DB2 etc) into one simple model
Microsoft Public License
293 stars 128 forks source link

PostgreSQL: Cannot use functions as default value #131

Closed Arnagos closed 2 years ago

Arnagos commented 2 years ago

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.

Arnagos commented 2 years ago

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.

martinjw commented 2 years ago

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!