public override void ExplicitVisit(DefaultConstraintDefinition node) { _buffer.Append("\talter column "); node.Column.Accept(this); _buffer.Append(" set default "); ScalarExpression expression = node.Expression; while (expression is ParenthesisExpression) { expression = ((ParenthesisExpression)expression).Expression; } string columnName = node.Column.Value; PgTableColumn column = _table.Columns[columnName]; if (expression is IntegerLiteral literal) { string value = literal.Value; if (column.DataType == "bool") { if (value == "0") { value = "(\'f\')"; } else { value = "(\'t\')"; } _buffer.Append(value); return; } } else if (expression is FunctionCall call) { string functionName = call.FunctionName.Value.ToLower(); switch (functionName) { case "getutcdate": _buffer.Append("(current_timestamp at time zone 'UTC')"); return; case "getdate": _buffer.Append("(localtimestamp)"); return; case "suser_sname": _buffer.Append("(session_user)"); return; default: throw new InvalidOperationException($"unsupported function {functionName}"); } } _buffer.Append("("); expression.Accept(this); _buffer.Append(")"); }
public ScalarExpression ReplaceExpression(ScalarExpression expression) { var directReplaced = ReplaceExpression(expression, out _); if (directReplaced != expression) { return(directReplaced); } expression.Accept(this); return(expression); }