[Sqlalchemy-tickets] Issue #3459: Add .cast shortcut method (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
|
From: Sebastian B. <iss...@bi...> - 2015-06-19 08:27:12
|
New issue 3459: Add .cast shortcut method https://bitbucket.org/zzzeek/sqlalchemy/issue/3459/add-cast-shortcut-method Sebastian Bank: I often find myself expecting columns/expressions/orm attributes to have a `.cast(type_)` shortcut method (just as they provide `.label`, `.desc`, `.op`, etc.), such that one could write `SELECT CAST(eggs AS text) FROM SPAM` as ``` from sqlalchemy import select, Text eggs_as_text = select([spam.c.eggs.cast(Text)]) ``` (cf. postgres `SELECT eggs::text FROM spam`) instead of ``` from sqlalchemy import select, cast, Text eggs_as_text = select([cast(spam.c.eggs, Text)]) ``` With the recent addition of a [cast method](http://docs.sqlalchemy.org/en/rel_1_0/dialects/postgresql.html#sqlalchemy.dialects.postgresql.JSONElement.cast) on `postgresql.JSONElement`, this might be a good occasion to add it (API consistency). In a quick test, this wasn't more than two lines in `sqlalchemy.sql.elements.ColumnElement`, but maybe I forgot some edge cases. |