Re: [sqlalchemy] Turning a Query instance into SQL (with parameters), need help w/ LIMIT/OFFSET in 0.7.x

2012-03-09 Thread Alex K
We use this recipe and in 0.7.5 it works ok with limit and offset. http://www.sqlalchemy.org/trac/wiki/UsageRecipes/old/DebugInlineParams On Fri, Mar 9, 2012 at 10:32 AM, Randy Syring rsyr...@gmail.com wrote: I found a recipe on stackoverflow for turning a query instance into a string,

Re: [sqlalchemy] duplicate key trick

2012-01-22 Thread Alex K
Thanks! Great work! :) On Sat, Jan 21, 2012 at 3:18 AM, Conor conor.edward.da...@gmail.com wrote: def get_constraint_name(e): # Unique constraint violations in PostgreSQL have error code 23505. if e.orig.pgcode == 23505: return re.search(r'^ERROR: duplicate key value violates

Re: [sqlalchemy] empty query

2011-12-11 Thread Alex K
I need EmptyQuery because query that returns from my function used for different cases, and if I return [], it will raise error, because [] not has query methods like order_by. e.g. query1 = getComments(user_id).order_by('comment.time_create desc') query2 = getComments(user_id).order_by('id')

Re: [sqlalchemy] default NULL

2011-11-11 Thread Alex K
Thanks, but if I need allow nullable primary_keys it not works. I tried: user_id = db.Column(db.Integer, db.ForeignKey('user.id', ondelete='SET NULL'), primary_key=True, nullable=True, server_default=text('NULL')) it generates CREATE TABLE user_ip ( user_id INTEGER DEFAULT NULL, PRIMARY KEY

Re: [sqlalchemy] default NULL

2011-11-11 Thread Alex K
=' 127.0.0.1/32') and it raise error: ArgumentError: Mapper Mapper|UserIp|user_ip could not assemble any primary key columns for mapped table 'user_ip' Thanks! On Fri, Nov 11, 2011 at 2:35 PM, Wichert Akkerman wich...@wiggy.net wrote: On 11/11/2011 11:20 AM, Alex K wrote: Thanks, but if I

Re: [sqlalchemy] Re: sqlalchemy from_statement dynamic attributes for python objects instances

2011-10-21 Thread Alex K
try doing: level in row instead of recompiling the query with __str__() each time, very expensive, also not very accurate Thanks! -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to

Re: [sqlalchemy] how to compile statement from string and params dict?

2011-10-21 Thread Alex K
Maybe compiler from sqlalchemy can help me? from sqlalchemy.sql import compiler from sqlalchemy.sql.expression import text t = text(st) c = compiler.SQLCompiler(db.engine.dialect, t) and now I don't know how pass the params dict to compiler. Thanks. On Fri, Oct 21, 2011 at 6:40 PM, Michael

Re: [sqlalchemy] Re: sqlalchemy from_statement dynamic attributes for python objects instances

2011-10-20 Thread Alex K
On Wed, Oct 19, 2011 at 7:57 PM, Michael Bayer mike...@zzzcomputing.comwrote: but I can't add options contains_eager like result = result.options(contains_eager(Comment.user)) Well no because you're digging way into RECURSIVE queries which SQLA doesn't yet support very nicely. Mapping

Re: [sqlalchemy] Re: sqlalchemy from_statement dynamic attributes for python objects instances

2011-10-20 Thread Alex K
: On Oct 20, 2011, at 4:03 AM, Alex K wrote: result2 = db.session.query(non_primary_mapper).from_statement('SELECT test.id AS test_id, test.user_id AS test_user_id, test.reply_id AS test_reply_id, test.text AS test_text FROM test LEFT OUTER JOIN user ON user.id = test.user_id LIMIT 1 OFFSET 0

Re: [sqlalchemy] Re: sqlalchemy from_statement dynamic attributes for python objects instances

2011-10-20 Thread Alex K
', content_comments_level_add) and it works. Thanks! On Thu, Oct 20, 2011 at 6:54 PM, Michael Bayer mike...@zzzcomputing.comwrote: On Oct 20, 2011, at 10:45 AM, Alex K wrote: I solve this problem with new custom Query class: it appears all you're doing is injecting an extra column

[sqlalchemy] expression inside mysql Interval statement

2009-06-19 Thread Alex K
Hi All, I need to construct the following query: select ADDDATE(start,INTERVAL rt_daily_days DAY) from _event where repeat_type = 1; and I have difficulties in dealing with the following statement: INTERVAL rt_daily_days DAY, how can I do this using sqlalchemy func interfaces?

[sqlalchemy] Application performance

2009-03-19 Thread Alex K
Hi All, I need an advice, take a look at this code sample: engine = create_engine(url,encoding = 'utf-8',echo = False,pool_size = 100) metadata = MetaData() object_table = Table('_object', metadata, Column('id', Integer, primary_key=True),

[sqlalchemy] Re: Application performance

2009-03-19 Thread Alex K
DB is utf-8 encoded/collated etc. On Mar 19, 1:22 pm, Noah Gift noah.g...@gmail.com wrote: On Thu, Mar 19, 2009 at 11:20 PM, Andreas Jung li...@zopyx.com wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 19.03.2009 11:14 Uhr, Alex K wrote: Well, it does not affect

[sqlalchemy] Re: delete failure with foreign key relations

2009-01-29 Thread Alex K
Well, this error says that you have rows in other(or same) tables referring to this row you are going to delete, and you should delete referring rows first. If you want SQLA to do it automatically, you need to use sessions and mappers (not raw SQL expression engine), more info here:

[sqlalchemy] Re: self referential eagerload issue

2009-01-23 Thread Alex K
Patch works like a charm! Thanks once again, Alex --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group,

[sqlalchemy] self referential eagerload issue

2009-01-22 Thread Alex K
Hi All! Assume we have the following setup: a_table = Table('A', metadata, Column('id', Integer, primary_key=True) ) b_table = Table('B', metadata, Column('id', Integer, primary_key=True), Column('parent_b1_id', Integer,

[sqlalchemy] Re: self referential eagerload issue

2009-01-22 Thread Alex K
() for now. On Jan 22, 2009, at 5:10 AM, Alex K wrote: Hi All! Assume we have the following setup: a_table = Table('A', metadata,                Column('id', Integer, primary_key=True)                ) b_table = Table('B', metadata,                Column('id', Integer, primary_key

[sqlalchemy] Re: It's possible to access a read-only table(without primarykey) in ORM?

2009-01-22 Thread Alex K
You can definitely access this table, using SQL engine only my_table = Table('my_table', metadata, Column('my_field', String) ) #now we can perform the query session.connection().execute(my_table.select()) #more info here:

[sqlalchemy] Re: Dynamic mapping strategy

2008-10-25 Thread Alex K
Hello Michael, JFYI - schema mapping approach worked fine, however I faced a new requirement to clear mappings in case if schema was altered (since I can not restart the web server), so I will try to clear partial mappers as you've suggested, Alex On 29 сент, 18:35, Alex K [EMAIL PROTECTED

[sqlalchemy] Holding connections

2008-10-19 Thread Alex K
Hi All, I get 'Mysql server has gone away' and 'failed to reconnect' errors, that's why I think that my app holds connections and never releases them. But the irony is that I'm issuing rollbacks or commits at the end of every request (rollbacks on any exception, commit if everything is ok) and

[sqlalchemy] Re: Selecting what properties of an object will be loaded

2008-10-17 Thread Alex K
in the database. Ants On Oct 16, 12:56 pm, Alex K [EMAIL PROTECTED] wrote: Hi All, I wonder if there is a way to set what columns of the object will be used during this particular query, to reduce the query in case if I need the object, but I don't need all object properties

[sqlalchemy] Selecting what properties of an object will be loaded

2008-10-16 Thread Alex K
Hi All, I wonder if there is a way to set what columns of the object will be used during this particular query, to reduce the query in case if I need the object, but I don't need all object properties. is something like this: session.query(User).load('column_a') possible? session.query([...])

[sqlalchemy] Re: Selecting what properties of an object will be loaded

2008-10-16 Thread Alex K
That's fine, but I'd like to do the same for columns On 16 окт, 13:50, [EMAIL PROTECTED] wrote: for relations, u can put deferred(name) and noload(name) in quety.options( ...). no idea for plain columns On Thursday 16 October 2008 12:56:19 Alex K wrote: Hi All, I wonder

[sqlalchemy] Re: How to filter values in PGArray

2008-10-02 Thread Alex K
Hi, Seems that you need to call a function, here are the docs describing how to do this: http://www.sqlalchemy.org/docs/05/sqlexpression.html#sql_everythingelse_functions Regards, Alex On Oct 2, 3:49 pm, Ye Xu [EMAIL PROTECTED] wrote: Hello Everyone, database table testArray Column |

[sqlalchemy] Re: how to join tables properly

2008-09-29 Thread Alex K
Hello, Ksenia, This may help: http://www.sqlalchemy.org/docs/05/mappers.html#advdatamapping_relation_strategies_containseager On Sep 29, 2:38 am, Ksenia [EMAIL PROTECTED] wrote: Hi list, I can't figure out a very simple thing. All I want is to do this query: select table1.A, table2.B,

[sqlalchemy] Re: Setting up a many-to-many relation with no right-hand-side table

2008-09-29 Thread Alex K
Not sure about append, but you can definitely use column_property for generated select property, more details here: http://www.sqlalchemy.org/docs/05/mappers.html#advdatamapping_mapper_expressions Alex On 29 сент, 16:03, Nick Murdoch [EMAIL PROTECTED] wrote: Hi everyone, I have an unusual

[sqlalchemy] Dynamic mapping strategy

2008-09-29 Thread Alex K
Hi All, My application uses XML schema to load tables, classes, set SQLA mapping and relations. Each processing node (thread or process, depends on config) does not know beforehand what type of mapping it will process, that's why I need to create mapping (parse schema, and generate classes) per

[sqlalchemy] Re: Dynamic mapping strategy

2008-09-29 Thread Alex K
Thanks for such a detailed response! I'll try schema caching approach and will bring back the results, Thanks again, Alex On 29 сент, 18:21, Michael Bayer [EMAIL PROTECTED] wrote: On Sep 29, 2008, at 9:30 AM, Alex K wrote: Hi All, My application uses XML schema to load tables

[sqlalchemy] Re: query over multiple any2many relations?

2008-09-26 Thread Alex K
Hi, I was only able to achieve this via joins and eagerloads, so I would be also interested in the relations based example Alex On 26 сент, 14:59, [EMAIL PROTECTED] wrote: hi say i have Person, Address, Street:  person has (many) addresess, address has (many) streets, ... could be more

[sqlalchemy] Comparable Property in partial selects

2008-09-26 Thread Alex K
Hi All, I have created comparable property JoinedValues that represents any joined columns, e.g. full name for first_name and last_name. Everything works, fine, except the moment when I try to select this property explicitly, e.g. like: session.query(User.full_name)... i get error 'ClauseList'

[sqlalchemy] Re: Comparable Property in partial selects

2008-09-26 Thread Alex K
Thanks, Michael. I've just tried your example with column_property, everything works fine, except one thing: Does column_property hides the properties it relies on? So, once I added full_name, last_name and first_name disappeared, is it possible to have them existing along with full_name?

[sqlalchemy] Re: Comparable Property in partial selects

2008-09-26 Thread Alex K
Sorry, I've re-checked, it was my typo, all properties co-exist ok, Thanks again, Alex On 26 сент, 21:37, Michael Bayer [EMAIL PROTECTED] wrote: On Sep 26, 2008, at 1:09 PM, Alex K wrote: Thanks, Michael. I've just tried your example with column_property, everything works fine, except

[sqlalchemy] Re: Problems with join query, can't figure out what's wrong. Noob alert!

2008-09-25 Thread Alex K
OK, I'm back again. Played with Elixir and was able to re-implement your example - got the query desired. However I've found a couple of strange parts of your code. 1. Why do you mix mapper(), Table and Elixir? Elixir creates tables and maps everything for you, this is what it was designed for.

[sqlalchemy] Re: Problems with join query, can't figure out what's wrong. Noob alert!

2008-09-24 Thread Alex K
Hi, Try to replace .join(Prosjekt,Sak.prosjektid) with the .join(Prosjekt,Sak.prosjekt) in your first query and write back, Alex On 23 сент, 12:38, olavgg [EMAIL PROTECTED] wrote: I've recently started using SQLAlchemy and is a newb. I have good SQL knowledge though. My first project with

[sqlalchemy] Re: Relations - How?

2008-09-24 Thread Alex K
Pylons and SQLAlchemy! On 23 Wrz, 12:16, Alex K [EMAIL PROTECTED] wrote: Hello, here is the answer: # -*- coding: utf-8 -*- from sqlalchemy import create_engine from sqlalchemy import Table, Column, Integer, String, Unicode, MetaData, ForeignKey from sqlalchemy.orm import

[sqlalchemy] Re: Problems with join query, can't figure out what's wrong. Noob alert!

2008-09-24 Thread Alex K
K, seems that I've found the root cause: When you are making the join from query, the syntax is: app.session.query(Sak).join(Sak.prosjektid).filter( where Sak.prosjektid is the relation property of the Sak class or you can specify the target in the tuples form:

[sqlalchemy] Re: Problems with join query, can't figure out what's wrong. Noob alert!

2008-09-24 Thread Alex K
it be an issue with Elixir which I'm using? Or with Plone/Five? What about just using a from_statement? On Sep 24, 3:16 pm, Alex K [EMAIL PROTECTED] wrote: K, seems that I've found the root cause: When you are making the join from query, the syntax is: app.session.query(Sak).join

[sqlalchemy] Re: Cyclic references and Nullable

2008-09-23 Thread Alex K
And how can you do this via explicit SQL? On 23 сент, 18:32, mraer [EMAIL PROTECTED] wrote: Suppose I have two classes of objects which have a reference to each other: Class A: b Class B: a Both references are mandatory so nullable = False I use post_update = True in relation function

[sqlalchemy] Re: dictionary mapping with foreignkey relations/association objects

2008-09-22 Thread Alex K
Hello Matt, this should help: you are using many-to-many relationship, (book_author_table - is your association table) please read this first: http://www.sqlalchemy.org/docs/05/mappers.html#advdatamapping_relation_patterns_manytomany After what you can turn to

[sqlalchemy] Re: About the mapping for many to many

2008-09-11 Thread Alex K
Hello, What do you mean by real value? You've got 2 perfect Category objects associatied with your Item, mosst.model.page.Category object at 0x020F67B0 - is just a string stamp of the object when converted to a string. you may want something like this: item.categories[0].name to access the name