Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VALUES clause in SQLAlchemy

Is there a way to build a Query object in SQLAlchemy which will be the equivalent of:

SELECT * FROM (VALUES (1, 2, 3)) AS sq;

From what I see in the documentation, the VALUES clause appears only in use with INSERT.

like image 327
vonPetrushev Avatar asked Sep 17 '13 19:09

vonPetrushev


1 Answers

This is now natively available in SQLAlchemy.

Your example would be written as:

from sqlalchemy import select, column, Integer
from sqlalchemy.sql import Values

select(Values(column('Number', Integer), name='sq').data([(1,), (2,), (3,)]))

There doesn't seem to be any documentation on this, but you can have a look at the test cases https://github.com/sqlalchemy/sqlalchemy/blob/master/test/sql/test_values.py

like image 94
tommyip Avatar answered Sep 22 '22 01:09

tommyip