[sqlalchemy] How to make use of bindparam() in a custom Compiled expression?

2015-11-19 Thread Юрий Пайков
I based my code on the Michaeil Bayer's answer to this Stack Overflow question . I extended it a little so it takes into account NULLs and ARRAY for Postgresql. class values(FromClause): named_with_column = True

Re: constraint names not as strict as expected

2015-11-19 Thread Chris Frey
On Wed, Nov 18, 2015 at 11:23:11PM -0500, Mike Bayer wrote: > if you change your naming convention, then that would show up as a bunch > of brand new constraints in the model and a whole bunch of constraints > removed in the model, so in theory would produce a lot of add constraint > / drop

Re: [sqlalchemy] How to make use of bindparam() in a custom Compiled expression?

2015-11-19 Thread Юрий Пайков
The problem is - I can't wrap my head round using it... Could you direct me to same compiled clause which uses bindparams? Or perhaps maybe to some documentation on SQLA internals, because it is quite difficult to track the whole query compilation process for me четверг, 19 ноября 2015 г.,

Re: [sqlalchemy] Is there an easy way to get the resulting types from text() query?

2015-11-19 Thread Mike Bayer
On 11/19/2015 12:42 PM, Naveen Michaud-Agrawal wrote: > Ah sorry, I wasn't clearer earlier. The text() call will take an > arbitrary SQL string from the user, so there's no easy way to know which > columns to pass into the .columns() call (short of parsing the statement > and then using

Re: [sqlalchemy] How to make use of bindparam() in a custom Compiled expression?

2015-11-19 Thread Mike Bayer
well what is the ARRAY data you're passing into it? can you provide a complete example? On 11/19/2015 02:04 PM, Юрий Пайков wrote: > The problem is - I can't wrap my head round using it... Could you > direct me to same compiled clause which uses bindparams? > Or perhaps maybe to some

[sqlalchemy] Inheritance and self.reference

2015-11-19 Thread Bernhard Radermacher
I am stumped... I have the following scenario: Two classes (Project and Package) inherit from class Container. Project is at the top-level of the hierarchy, and can contain Packages, Package must be contained in a Project or a different Package (i.e. a Container) and can contain other

Re: [sqlalchemy] How to make use of bindparam() in a custom Compiled expression?

2015-11-19 Thread Mike Bayer
On 11/19/2015 05:23 PM, Юрий Пайков wrote: > Oh, man I got it. Cannot imagine what kind of an insight hit me when I > figured it out! > Here is a test > case and final version of VALUES clause > > Btw, why there is no _type_api mapping for

Re: [sqlalchemy] Inheritance and self.reference

2015-11-19 Thread Mike Bayer
On 11/19/2015 02:38 PM, Bernhard Radermacher wrote: > I am stumped... > > I have the following scenario: Two classes (Project and Package) inherit > from class Container. Project is at the top-level of the hierarchy, and > can contain Packages, Package must be contained in a Project or a >

Re: [sqlalchemy] How to make use of bindparam() in a custom Compiled expression?

2015-11-19 Thread Юрий Пайков
Oh, man I got it. Cannot imagine what kind of an insight hit me when I figured it out! Here is a test case and final version of VALUES clause Btw, why there is no _type_api mapping for a list() python type

Re: [sqlalchemy] Inheritance and self.reference

2015-11-19 Thread Bernhard Radermacher
That works great, thanks. If I understand correctly, the inherit_condition is deduced automatically, when there is no other foreign key linking to the super-class... On Thursday, November 19, 2015 at 12:52:33 PM UTC-8, Michael Bayer wrote: > > > > the docs are slight here but the format is

Re: [sqlalchemy] How to make use of bindparam() in a custom Compiled expression?

2015-11-19 Thread Юрий Пайков
But if I used bound parameters in a query - wouldn't it be a solution? I mean, if a value for a bindparam is not inlined in a query and rather carried along - there is no need to quote it for the driver, is there? Like done for any other literal comparison, for example. The driver will insert

Re: [sqlalchemy] How to make use of bindparam() in a custom Compiled expression?

2015-11-19 Thread Mike Bayer
On 11/19/2015 10:07 AM, Юрий Пайков wrote: > But if I used bound parameters in a query - wouldn't it be a solution? > I mean, if a value for a bindparam is not inlined in a query and rather > carried along - there is no need to quote it for the driver, is there? > Like done for any other

Re: [sqlalchemy] Is there an easy way to get the resulting types from text() query?

2015-11-19 Thread Mike Bayer
On 11/19/2015 09:48 AM, Naveen Michaud-Agrawal wrote: > I'm building a small GUI on top of sqlalchemy and would like to change > the alignment of the columns based on the type (string or numeric). This > works fine when the query is generated through query objects (using Mike > Bayer's answer >

[sqlalchemy] Is there an easy way to get the resulting types from text() query?

2015-11-19 Thread Naveen Michaud-Agrawal
I'm building a small GUI on top of sqlalchemy and would like to change the alignment of the columns based on the type (string or numeric). This works fine when the query is generated through query objects (using Mike Bayer's answer from

Re: constraint names not as strict as expected

2015-11-19 Thread Mike Bayer
On 11/19/2015 04:01 AM, Chris Frey wrote: > On Wed, Nov 18, 2015 at 11:23:11PM -0500, Mike Bayer wrote: >> if you change your naming convention, then that would show up as a bunch >> of brand new constraints in the model and a whole bunch of constraints >> removed in the model, so in theory

Re: [sqlalchemy] Adding a condition to an aliased subquery generates a Cartesian product (and incorrect results)

2015-11-19 Thread Mike Bayer
On 11/19/2015 12:38 AM, Laura Pearlman wrote: > Hi, > > When I do this in Python: > > metadata = MetaData() > person = Table('person', metadata, Column('name', String), Column('id', > Integer)) > base_query = select(person.c).alias('person_alias').select() > query =

Re: [sqlalchemy] How to make use of bindparam() in a custom Compiled expression?

2015-11-19 Thread Mike Bayer
On 11/19/2015 05:29 AM, Юрий Пайков wrote: > I based my code on the Michaeil Bayer's answer to this Stack Overflow > question > . > I extended it a little so it takes into account NULLs and ARRAY for > Postgresql. > >

Re: [sqlalchemy] Is there an easy way to get the resulting types from text() query?

2015-11-19 Thread Naveen Michaud-Agrawal
Ah sorry, I wasn't clearer earlier. The text() call will take an arbitrary SQL string from the user, so there's no easy way to know which columns to pass into the .columns() call (short of parsing the statement and then using reflected MetaData to populate the columns from the relevant tables