[sqlalchemy] ORM relationships and (PostgreSQL) partition constraint-exclusion

2013-12-05 Thread Adrian
Hi All, I have a few partitioned tables in my PostgreSQL database but I do not know yet how to make the ORM relationship() with partition constraint-exclusionhttp://www.postgresql.org/docs/9.3/static/ddl-partitioning.html#DDL-PARTITIONING-CONSTRAINT-EXCLUSION on the instance level.

Re: [sqlalchemy] ORM relationships and (PostgreSQL) partition constraint-exclusion

2013-12-05 Thread Adrian Schreyer
Never mind, the problem was that I specified the clause in a secondaryjoin and not in the primaryjoin of the relationship(). On Thu, Dec 5, 2013 at 10:44 AM, Adrian adrian.schre...@gmail.com wrote: Hi All, I have a few partitioned tables in my PostgreSQL database but I do not know yet how

Re: [sqlalchemy] fake models ?

2013-12-05 Thread Richard Gerd Kuesters
ok, let's see if I can explain the scenario better :D first, i'm using schematics http://schematics.readthedocs.org/ to define arbitrary models for message exchange between processes, ui, events and so on. based on a json schema (that the schematics model generates), i'm able to store data on

[sqlalchemy] Re: PostgreSQL Tsvector type

2013-12-05 Thread Noufal Ibrahim
Hello Michael, Michael Bayer mike_mp at zzzcomputing.com writes: the TsVector type looks perfect! if you were to package that up for inclusion, it would likely subclass TypeEngine and you’d implement PGTypeCompiler.visit_TSVECTOR.we appear to have a little bit of “tsvector” code

[sqlalchemy] postgres schema per model

2013-12-05 Thread Richard Gerd Kuesters
hi all! another question: i have a postgres database, and i would like to work with schemas for module models. so far so good, but i didn't find much information besides it is available in sa docs. so, i came into this:

Re: [sqlalchemy] ORM relationships and (PostgreSQL) partition constraint-exclusion

2013-12-05 Thread Michael Bayer
On Dec 5, 2013, at 6:57 AM, Adrian Schreyer adrian.schre...@gmail.com wrote: Actually that was a bit too early but I tracked the problem down to the many-to-many relationship. Parameters are only interpolated (e.g. %(param_1)s) for the primaryjoin to the secondary table. Is there a

Re: [sqlalchemy] postgres schema per model

2013-12-05 Thread Michael Bayer
here’s an example, works on this end: from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class AltSchema(object): __table_args__ = {schema: test_schema} class A(AltSchema, Base): __tablename__ = 'a'

[sqlalchemy] Re: postgres schema per model

2013-12-05 Thread Jonathan Vanasco
this is a really great idea! thanks for asking this question. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to

Re: [sqlalchemy] postgres schema per model

2013-12-05 Thread Richard Gerd Kuesters
ha! thanks Mike! i must have been stupid somewhere. i could say that i did that but, since it didn't worked then, i can say that my code was wrong somehow :) my best regards, richard. On 12/05/2013 01:37 PM, Michael Bayer wrote: here’s an example, works on this end: from sqlalchemy

Re: [sqlalchemy] Re: postgres schema per model

2013-12-05 Thread Richard Gerd Kuesters
well ... i'm glad i helped you somehow, even though it was a question :D cheers, richard. On 12/05/2013 01:40 PM, Jonathan Vanasco wrote: this is a really great idea! thanks for asking this question. -- You received this message because you are subscribed to the Google Groups sqlalchemy

[sqlalchemy] ORM events order

2013-12-05 Thread Tim Kersten
Hi Folks, Is the order ORM events ( http://docs.sqlalchemy.org/en/rel_0_9/orm/events.html ) are fired in deterministic and guaranteed to be the same every time? I've searched the docs and google but couldn't anything relating to their relative order. Cheers, Tim -- You received this

Re: [sqlalchemy] fake models ?

2013-12-05 Thread Michael Bayer
On Dec 5, 2013, at 6:16 AM, Richard Gerd Kuesters rich...@humantech.com.br wrote: ok, let's see if I can explain the scenario better :D first, i'm using schematics http://schematics.readthedocs.org/ to define arbitrary models for message exchange between processes, ui, events and so on.

[sqlalchemy] Expected behaviour for Oracle's lost contact

2013-12-05 Thread Mariano Mara
Hi there, in one application I am using sqlalchemy 0.7.8 against Oracle 11 release 1 and I am hitting Oracle's lost contact more times than I would like to. Since the app seems unable to recover from the error, I have to restart it completely (it is a pyramid app). According to this

Re: [sqlalchemy] ORM events order

2013-12-05 Thread Michael Bayer
On Dec 5, 2013, at 10:51 AM, Tim Kersten t...@io41.com wrote: Hi Folks, Is the order ORM events ( http://docs.sqlalchemy.org/en/rel_0_9/orm/events.html ) are fired in deterministic and guaranteed to be the same every time? I've searched the docs and google but couldn't anything

Re: [sqlalchemy] ORM relationships and (PostgreSQL) partition constraint-exclusion

2013-12-05 Thread Adrian Schreyer
Given the three mappings *First*, *Second* and *Partitioned*, I want to declare a relationship between *First* and *Partitioned*. The problem is that *Partitioned* is partitioned by partition_key which is a column in *First* but not in *Second*. *Second* however contains the identifier that

Re: [sqlalchemy] Expected behaviour for Oracle's lost contact

2013-12-05 Thread Michael Bayer
On Dec 5, 2013, at 10:54 AM, Mariano Mara mariano.m...@gmail.com wrote: Hi there, in one application I am using sqlalchemy 0.7.8 against Oracle 11 release 1 and I am hitting Oracle's lost contact more times than I would like to. Since the app seems unable to recover from the error, I have

Re: [sqlalchemy] ORM relationships and (PostgreSQL) partition constraint-exclusion

2013-12-05 Thread Michael Bayer
oh, you want to refer to the tertiary table in both the primary and secondary join.so right this pattern does not correspond to the A-secondary-B pattern and isn’t really a classic many-to-many. a quick way to map these are to use non primary mappers (was going to just paraphrase, but let

Re: [sqlalchemy] fake models ?

2013-12-05 Thread Richard Gerd Kuesters
the vertical mapper example was kind of a base for me to develop my eav system. i have added also a table that defines the structure of the entity, since then I use schematics (and its json schema import - export utility). it's very handy. i think that a pseudo-code can explain a little

Re: [sqlalchemy] ORM events order

2013-12-05 Thread Tim Kersten
thank you. What of the relative ordering of the different ORM event types? i.e. before_flush before_delete after_flush etc When looking at before_flush I see the before_delete has not yet been fired, yet is has been fired in the after_flush. Is this guaranteed to always be the case? On 5

Re: [sqlalchemy] ORM events order

2013-12-05 Thread Michael Bayer
On Dec 5, 2013, at 12:14 PM, Tim Kersten t...@io41.com wrote: thank you. What of the relative ordering of the different ORM event types? i.e. before_flush before_delete after_flush etc When looking at before_flush I see the before_delete has not yet been fired, yet is has been

[sqlalchemy] question about race conditions

2013-12-05 Thread Jonathan Vanasco
i'm looking at moving some raw sql in twisted to SqlAlchemy and have a question. I have a multi-threaded twisted daemon that tends to generate a lot of race conditions on a few tables that are frequently hit. I get integrity errors from something like this : domain = SELECT * FROM

Re: [sqlalchemy] ORM relationships and (PostgreSQL) partition constraint-exclusion

2013-12-05 Thread Adrian Schreyer
The partitioned relationship actually referred to the tertiary table in both the primary and secondary join - the problem for me was that in the primaryjoin primaryjoin=and_(First.first_id==Second.first_id, First.partition_key==Partitioned.partition_key) only First.first_id will be interpolated

Re: [sqlalchemy] Expected behaviour for Oracle's lost contact

2013-12-05 Thread Michael Bayer
also note if you really want to prevent disconnects at the top of a transaction, you can use a pessimistic approach, see http://docs.sqlalchemy.org/en/rel_0_9/core/pooling.html?highlight=pessimistic#disconnect-handling-pessimistic . On Dec 5, 2013, at 11:05 AM, Michael Bayer

Re: [sqlalchemy] question about race conditions

2013-12-05 Thread Michael Bayer
On Dec 5, 2013, at 2:24 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Dec 5, 2013, at 1:25 PM, Jonathan Vanasco jonat...@findmeon.com wrote: i'm looking at moving some raw sql in twisted to SqlAlchemy and have a question. I have a multi-threaded twisted daemon that tends to

Re: [sqlalchemy] Expected behaviour for Oracle's lost contact

2013-12-05 Thread Mariano Mara
On jue 05 dic 2013 16:19:14 ART, Michael Bayer wrote: also note if you really want to prevent disconnects at the top of a transaction, you can use a pessimistic approach, see http://docs.sqlalchemy.org/en/rel_0_9/core/pooling.html?highlight=pessimistic#disconnect-handling-pessimistic .

Re: [sqlalchemy] ORM relationships and (PostgreSQL) partition constraint-exclusion

2013-12-05 Thread Adrian Schreyer
I will try this out then, thanks for your help! I assume this works in 0.9 only? On Thu, Dec 5, 2013 at 7:18 PM, Michael Bayer mike...@zzzcomputing.comwrote: With the example I gave, when accessing .partitioned on a First instance, the lazy loader will convert all columns from “First” into a

Re: [sqlalchemy] ORM relationships and (PostgreSQL) partition constraint-exclusion

2013-12-05 Thread Michael Bayer
it should work in 0.8 as well (and can be done even in 0.7 with some adjustments), just not the more optimized nested JOIN part. On Dec 5, 2013, at 2:41 PM, Adrian Schreyer adrian.schre...@gmail.com wrote: I will try this out then, thanks for your help! I assume this works in 0.9 only?

Re: [sqlalchemy] question about race conditions

2013-12-05 Thread Jonathan Vanasco
oh that's great - I didn't expect SqlAlchemy to aggregate/support the different driver errors like that! thanks so much, Michael! -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it,

[sqlalchemy] creating a functional index for XML

2013-12-05 Thread Christian Lang
Hi, I'm trying to create the following index (on PostgreSQL) with SQLAlchemy 0.8: CREATE INDEX doc_idx ON xmltab (CAST((xpath('//@bla', doc))[1] AS TEXT)); (where doc is a column of type XML) I got this far: Index(doc_idx, cast((func.xpath('//@bla', xmlTable.c.doc))[1], TEXT)) but get the

Re: [sqlalchemy] question about race conditions

2013-12-05 Thread Julien Cigar
On Thu, Dec 05, 2013 at 10:25:46AM -0800, Jonathan Vanasco wrote: i'm looking at moving some raw sql in twisted to SqlAlchemy and have a question. I have a multi-threaded twisted daemon that tends to generate a lot of race conditions on a few tables that are frequently hit. I get

Re: [sqlalchemy] creating a functional index for XML

2013-12-05 Thread Michael Bayer
I think if you give your func.xpath a datatype of pg.ARRAY(of whatever) you’ll get it: func.xpath(…, type_=postgresql.ARRAY)[1] from sqlalchemy import func, String from sqlalchemy.dialects import postgresql print func.xpath('something', 'somethingelse',

Re: [sqlalchemy] fake models ?

2013-12-05 Thread Michael Bayer
Overall the different pieces aren’t making sense entirely. We have the notion of a “schema”, stored in the database - that is, Entity/Attribute. Those tables are fixed per type. It can tell me for example that there’s a “Person” type with two attributes associated, “name” and “website”. So

Re: [sqlalchemy] creating a functional index for XML

2013-12-05 Thread Christian Lang
Thanks for the quick reply. Getting closer... I changed the code to idx = Index(doc_idx, cast((func.xpath('//@bla', xmlTable.c.doc, type_=postgresql.ARRAY(String([1].compile(dialect=postgresql.dialect()), TEXT)) idx.create(engine) and the first line is now OK. But the second line

Re: [sqlalchemy] creating a functional index for XML

2013-12-05 Thread Michael Bayer
OK well the compile(dialect=…) was just to illustrate the string form, we don’t put that in the Index, so that way the expression still provides access to the column, which it needs to search for in order to get at the table: xmlTable = Table('xmltable', m, Column('doc', TEXT)) idx =

Re: [sqlalchemy] creating a functional index for XML

2013-12-05 Thread Christian Lang
I see, thanks for clarifying. I think it fails in PG because of a missing pair of parentheses. SA generates: CREATE INDEX doc_idx ON xmltab (CAST(xpath('//@value_dbl', doc)[1] AS TEXT)) but it should be: CREATE INDEX doc_idx ON xmltab (CAST((xpath('//@value_dbl', doc))[1] AS TEXT)) Subtle

Re: [sqlalchemy] creating a functional index for XML

2013-12-05 Thread Michael Bayer
parens can be forced using Grouping from sqlalchemy.sql.expression import Grouping idx = Index(doc_idx, cast( Grouping(func.xpath( '//@bla', xmlTable.c.doc, type_=postgresql.ARRAY(String())

Re: [sqlalchemy] creating a functional index for XML

2013-12-05 Thread Christian Lang
Wonderful, that did it! Thanks so much. On Thursday, December 5, 2013 3:01:04 PM UTC-8, Michael Bayer wrote: parens can be forced using Grouping from sqlalchemy.sql.expression import Grouping idx = Index(doc_idx, cast( Grouping(func.xpath(