Re: [sqlalchemy] Does SQLAlchemy support UPDATE...FROM syntax for postgres?

2014-04-10 Thread Joe Dallago
Awesome! This is exactly what I needed, thanks Mike. On Thu, Apr 10, 2014 at 10:17 PM, Michael Bayer wrote: > we do UPDATE..FROM but getting the VALUES thing in there requires some > extra recipes as we don't have that structure built in right now. also > the alias part of it where it names o

Re: [sqlalchemy] Does SQLAlchemy support UPDATE...FROM syntax for postgres?

2014-04-10 Thread Michael Bayer
we do UPDATE..FROM but getting the VALUES thing in there requires some extra recipes as we don't have that structure built in right now. also the alias part of it where it names out the columns in the AS portion is not natively built in either. The recipe is here: https://bitbucket.org/zzze

[sqlalchemy] Does SQLAlchemy support UPDATE...FROM syntax for postgres?

2014-04-10 Thread Joe Dallago
I want to write a query like so with SQLAlchemy: UPDATE mytable SET mytext = myvalues.mytext, myint = myvalues.myint FROM ( VALUES (1, 'textA', 99), (2, 'textB', 88), ...) AS myvalues (mykey, mytext, myint) WHERE mytable.mykey = myvalues.mykey Is this kind of thing supported

Re: [sqlalchemy] Replacing viewonly relationship properties in child classes

2014-04-10 Thread Michael Bayer
Not sure what the appropriate answer is, obviously the warning is there because people were mis-configuring their relationships and getting the wrong results. What exactly is the use case for restating the same relationship several times under the same name? If these relationships extend fr

Re: [sqlalchemy] Field in my query is a SELECT MAX FROM using a GROUP BY. How to deal with it?

2014-04-10 Thread Michael Bayer
On Apr 10, 2014, at 3:00 PM, Mauricio de Abreu Antunes wrote: > > I am not understanding the docs because they only talk about a subselect > inside the WHERE. What I am doing here is retrieving a MAX(field) from a > SELECT. > > Can someone guide me to the right direction? Thanks! the query

Re: [sqlalchemy] Replacing viewonly relationship properties in child classes

2014-04-10 Thread Konsta Vesterinen
Well the problem is this functionality will be part of SQLAlchemy-Continuum (versions relationships for entities using join table inheritance). It would be ugly if an extension for SQLAlchemy would throw warnings for certain mapper scenarios. Also I'm using warnings.simplefilter('error', sa.exc

Re: [sqlalchemy] Reuse pre-defined Enum?

2014-04-10 Thread Michael Bayer
On Apr 10, 2014, at 1:12 PM, Nguyễn Hồng Quân wrote: > > Before, I had gender_type declared inline in model A (gender = > Column(Enum('male', 'female', name='gender_type'))). > Now I add model B and also want to reuse the gender_type in model A. So, I > bring gender_type out and link to it f

Re: [sqlalchemy] Replacing viewonly relationship properties in child classes

2014-04-10 Thread Michael Bayer
what happens if you just ignore the warning? i think it might work anyway: from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class A(Base): __tablename__ = 'a' id = Column(Integer, primary_key=True)

[sqlalchemy] Field in my query is a SELECT MAX FROM using a GROUP BY. How to deal with it?

2014-04-10 Thread Mauricio de Abreu Antunes
Hello list, I am refactoring some RAW SQL to use SQL Alchemy ORM Query object (session.query). What I have so far is a SQL to reproduce using SQL Alchemy: My SQL is this: 1. SELECT DATE_FORMAT(DATE, '%Y%m%d') AS `date`, 2. `Hour` AS `hour`, 3. `Minute` AS `minute`, (MAX(TotalMBs)*8/5/

Re: [sqlalchemy] Reuse pre-defined Enum?

2014-04-10 Thread Nguyễn Hồng Quân
Hi Michael, On Mon, Dec 16, 2013 at 12:37 AM, Michael Bayer wrote: > > On Dec 15, 2013, at 4:16 AM, Hồng Quân Nguyễn > wrote: > > Hi all, > > Assume that I have this model > > class ModelA: > gender = Column(Enum('male', 'female', name='gender_type')) > > and in another ModelB, I want to

[sqlalchemy] Replacing viewonly relationship properties in child classes

2014-04-10 Thread Konsta Vesterinen
Hi, I have a situation where I have three classes A, B and C with B and C inheriting class A. Now each of these classes also has a version class, lets call them AVersion, BVersion and CVersion. The inheritance tree is the same: BVersion and CVersion inherit AVersion. What I want to achieve is

Re: [sqlalchemy] Is it possible to create a filter 'string' LIKE column + '%'?

2014-04-10 Thread Mark Bird
That's perfect. Thanks! On Thursday, 10 April 2014 11:38:24 UTC+1, Simon King wrote: > > You can also use sqlalchemy.literal, which returns an object that you > can treat like a column: > > sqlalchemy.literal('string').like('whatever') > > You may also be interested in the 'startswith' shortc

Re: [sqlalchemy] Is it possible to create a filter 'string' LIKE column + '%'?

2014-04-10 Thread Simon King
You can also use sqlalchemy.literal, which returns an object that you can treat like a column: sqlalchemy.literal('string').like('whatever') You may also be interested in the 'startswith' shortcut, which calls .like under the hood sqlalchemy.literal('string').startswith(yourcolumn) Simon O

Re: [sqlalchemy] Is it possible to create a filter 'string' LIKE column + '%'?

2014-04-10 Thread Mark Bird
I'm sorry, forget my last response, I see what you mean now. Thanks a lot! On Thursday, 10 April 2014 11:31:23 UTC+1, Gunnlaugur Briem wrote: > > Hi, > > See ColumnElement docs: > > > http://docs.sqlalchemy.org/en/rel_0_9/core/sqlelement.html#sqlalchemy.sql.expression.ColumnElement > > ... for yo

Re: [sqlalchemy] Is it possible to create a filter 'string' LIKE column + '%'?

2014-04-10 Thread Mark Bird
Hi, thanks but I'm not talking about calling like on a column - I need to call like on a string literal. I tried doing text('string').like() but that doesn't work either. On Thursday, 10 April 2014 11:31:23 UTC+1, Gunnlaugur Briem wrote: > > Hi, > > See ColumnElement docs: > > > http://docs.sq

Re: [sqlalchemy] Is it possible to create a filter 'string' LIKE column + '%'?

2014-04-10 Thread Gunnlaugur Thor Briem
Hi, See ColumnElement docs: http://docs.sqlalchemy.org/en/rel_0_9/core/sqlelement.html#sqlalchemy.sql.expression.ColumnElement ... for your specific example you can call .like(...) on column clauses: >>> print Column('foo', Text).like('bar%baz') foo LIKE :foo_1 More generally, if you wanted so

[sqlalchemy] Is it possible to create a filter 'string' LIKE column + '%'?

2014-04-10 Thread Mark Bird
I can't seem to find a way to do this without passing raw SQL to .filter() I could just do: .filter(column == func.substring('string', 1, func.char_length(column))) but is it possible to do it with LIKE? I.e. I need to return all rows that match the beginning of a string, so for 'string' I cou