GHC 2019-06-25

2 comments.

, https://git.io/fjrll in sqlalchemy/alembic
(By the way, I know how to work around this: explicitly defining the column in `reflected_args`.)

, https://git.io/fjrl8 in sqlalchemy/alembic
SQLite reflection: parentheses wrongly stripped from expression in default clause
=================================================================================

I have a table (SQLite) with a column that looks like

```sql
created_at DATETIME DEFAULT (datetime('now', 'localtime')) NOT NULL,
```

The parentheses around `datetime('now', 'localtime')` are syntactically necessary, without which one would get a syntax error:

> The DEFAULT clause specifies a default value to use for the column if no value is explicitly provided by the user when doing an INSERT. If there is no explicit DEFAULT clause attached to a column definition, then the default value of the column is NULL. An explicit DEFAULT clause may specify that the default value is NULL, a string constant, a blob constant, a signed-number, or **any constant expression enclosed in parentheses**.

https://www.sqlite.org/lang_createtable.html (emphasis mine)

When I use `op.batch_alter_table`, the reflected column's `server_default` is a text clause `datetime('now', 'localtime')`, without parentheses, so when alembic attempts to create the new table it fails:

```sql
CREATE TABLE _alembic_tmp_foo (
    ...
	created_at DATETIME DEFAULT datetime('now', 'localtime') NOT NULL, -- syntax error
)
```

I'm new to SQLA and Alembic so please excuse me if the fault is on me.