Re: [sqlalchemy] Determination of string lengths

2015-12-10 Thread 'Robert Forkel' via sqlalchemy
I don't know which database you are using, but in postgresql there certainly is a function called "length" (see http://www.postgresql.org/docs/9.1/static/functions-string.html) On Thu, Dec 10, 2015 at 2:04 PM, SF Markus Elfring < elfr...@users.sourceforge.net> wrote: > > As stated in the docs: >

Re: [sqlalchemy] Determination of string lengths

2015-12-10 Thread &#x27;Robert Forkel' via sqlalchemy
As stated in the docs: "Note that any name not known to func generates the function name as is - there is no restriction on what SQL functions can be called, known or unknown to SQLAlchemy, built-in or user

Re: [sqlalchemy] How can I keep SQLAlchemy DB connection alive for always?

2014-10-14 Thread Robert Forkel
Pessimistic disconnect handling may be what you are looking for: http://docs.sqlalchemy.org/en/latest/core/pooling.html#disconnect-handling-pessimistic On Tue, Oct 14, 2014 at 9:27 PM, Eren Gölge wrote: > I a create a session with these following lines; > > > Base = declarative_base() > > engi

Re: [sqlalchemy] SQLAlchemy 0.9.2 UnicodeEncodeErrors with PG 9.3.2 on Amazon RDS

2014-02-19 Thread Robert Forkel
FWIW I'm seeing not reproducible UnicodeEncodeErrors in my production systems, too. Alas only on ones with heavier load, and also with sqlalchemy 0.7.9. On Wed, Feb 19, 2014 at 3:45 PM, Michael Bayer wrote: > > On Feb 19, 2014, at 3:03 AM, Valentino Volonghi > wrote: > > > > >> 4. is this error

Re: [sqlalchemy] Build Query Without Objects

2014-01-14 Thread Robert Forkel
guess this could help: http://docs.sqlalchemy.org/en/rel_0_9/core/tutorial.html#selecting best robert On Tue, Jan 14, 2014 at 4:11 PM, Alex Meadows wrote: > Greetings, > > I've been reading through the docs and am still very new to SQLAlchemy but > haven't found an answer to my question. I am

Re: [sqlalchemy] query results are not converted to specialized class with joined table inheritance

2013-07-26 Thread Robert Forkel
at the column coming back which represents the > "discriminator". that value is what determines the type. > > > On Jul 26, 2013, at 11:20 AM, Robert Forkel > wrote: > > hi all, > i have a problem with joined table inheritance, which seems pretty > difficul

[sqlalchemy] query results are not converted to specialized class with joined table inheritance

2013-07-26 Thread Robert Forkel
hi all, i have a problem with joined table inheritance, which seems pretty difficult to boil down to a minimal test case; so I'm just throwing a prose description out, hoping someone encountered and solved this: When querying, the results are not converted to instances of the specialized class,

Re: [sqlalchemy] using an unmapped object to get the mapped object from a session

2013-01-11 Thread Robert Forkel
Transient Am 11.01.2013 22:33 schrieb "Chris Withers" : > On 11/01/2013 20:01, Michael Bayer wrote: > >> >> On Jan 11, 2013, at 1:37 PM, Chris Withers wrote: >> >> On 11/01/2013 15:26, Michael Bayer wrote: >>> what is it looking up ?what's a "myobj" ? >> > > An unmappe

Re: [sqlalchemy] Storing a two dimensional list structure with different item types in Postgres 9.1

2012-12-20 Thread Robert Forkel
If you are only after storage (leaving aside querying, indexing, ...) a simple JSON column [1] could do. The advantage being portability between databases. I've used this to as simple key-value store of data associated with a row. regards robert [1] http://docs.sqlalchemy.org/en/rel_0_8/core/types

Re: [sqlalchemy] Creating a feed related to different object type

2012-11-27 Thread Robert Forkel
hi, i used to do something like this, i.e. adding information about urls, views, etc. to sqlalchemy models, but found this to be inflexibel. Now I keep URL-related information in the web app's routing component, and to solve problems like the one you pose, I use zca adapters [1] (which is easier wh

Re: [sqlalchemy] Inheriting a functionality in SQLA

2012-11-20 Thread Robert Forkel
As far as i know each declarative Base has its own metadata registry. You are using two. Why not use multiple mixins to inherit the columns? Am 20.11.2012 10:31 schrieb "AlexVhr" : > I'm trying to incapsulate some functionality (some columns mainly) into > base classes to inherit my models from t

Re: [sqlalchemy] Audit Table / History Table

2012-11-19 Thread Robert Forkel
http://docs.sqlalchemy.org/en/rel_0_8/orm/examples.html#versioned-objects looks like what you may want. On Mon, Nov 19, 2012 at 9:10 PM, LPG wrote: > I'm looking for details on implementing an audit table, either through sqla > itself or in a way that plays nicely with sqla. It looks like there u

Re: [sqlalchemy] Documenting sqlalchemy objects via sphinx automodule

2012-09-04 Thread Robert Forkel
I've been hitting the same wall, and decided that autoload was the wrong way to go. Once you want to generate documentation for a database from the models, you typically do not want allow frequent changes of the DB structure anymore. So at this point, I just wrote a script to create basic model cla

Re: [sqlalchemy] __main__ error

2012-08-29 Thread Robert Forkel
you could create a method on the Boreholes mapper to convert an instance to geojson (which I assume to be some sort of dictionary): class Boreholes(mybase): ... def geojson(self): return dict([(attr, getattr(self, attr, None)) for attr in ['latitude', 'longitude', .. whatever else

Re: [sqlalchemy] __main__ error

2012-08-29 Thread Robert Forkel
for borehole in alldata: for attr in sorted(filter(lambda a: not a.startswith('_'), dir(borehole))): print attr, getattr(borehole, attr) could do the trick On Wed, Aug 29, 2012 at 1:24 PM, Gery . wrote: > > thanks Robert, using your suggestion I get: > > ['__class__', '__delattr__',

Re: [sqlalchemy] __main__ error

2012-08-29 Thread Robert Forkel
doesn't look like an error to me. It's just the result of your print alldata call. It depends on Postgis which attributes are available on the Borehole instances, but you could use print dir(alldata[0]) to get an idea about what is available. On Wed, Aug 29, 2012 at 12:37 PM, Gery . wrote: >

Re: [sqlalchemy] mapping postgres sequences?

2012-05-29 Thread Robert Forkel
example now includes your second question: from sqlalchemy import Sequence, create_engine, MetaData, Column, Integer from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class Model(Base): __tablename__ = 'model' col = Column(Integer, Sequence('seq'), prima

Re: [sqlalchemy] mapping postgres sequences?

2012-05-29 Thread Robert Forkel
working example for the first question: from sqlalchemy import Sequence, create_engine, MetaData if __name__ == "__main__": md = MetaData() e = create_engine('postgresql://rforkel@/test1', echo=True) md.bind = e s = Sequence('name', metadata=md) md.create_all() print list(

Re: [sqlalchemy] mapping postgres sequences?

2012-05-29 Thread Robert Forkel
ad 1) from http://docs.sqlalchemy.org/en/rel_0_7/core/schema.html#defining-sequences : The Sequence object also has the ability to be executed standalone like a SQL expression, which has the effect of calling its “next value” function: seq = Sequence('some_sequence') nextid = connection.execute(s

Re: [sqlalchemy] How to get DDL string from metadata?

2012-04-24 Thread Robert Forkel
[1] > http://docs.sqlalchemy.org/en/latest/core/engines.html#sqlalchemy.create_engine > > > On 24.4.2012, at 9:50, Robert Forkel wrote: > >> what I do is using a custom engine like this: >> >> >>        out = StringIO() >>        def dump(sql, *mu

Re: [sqlalchemy] How to get DDL string from metadata?

2012-04-24 Thread Robert Forkel
what I do is using a custom engine like this: out = StringIO() def dump(sql, *multiparams, **params): # make sure the mock engine appends ';' to the end of DDL statements # so they can be pasted and run in sql developer! out.write(('%s' % sql.co

Re: [sqlalchemy] how to use substring in the where clause?

2012-03-08 Thread Robert Forkel
t func > and > from sqlalchemy import func > > the second import is what I found out while experimenting with the query and > after I saw your reply, I tried your code and both works the same. > > > > > On 08-03-2012 12:39, Robert Forkel wrote: >> >> sq

Re: [sqlalchemy] how to use substring in the where clause?

2012-03-08 Thread Robert Forkel
sqlalchemy.sql.expression.func may work for this: from sqlalchemy.sql.expression import func ... q_doc.filter(func.substring(model.Doc.FileNameStr, 22, 1)==search_str) ... 2012/3/8 Timuçin Kızılay : > I have a query contains SUBSTRING in where clause: > > Select top 100 * from _Doc > where SUBST

[sqlalchemy] CREATE SEQUENCE issued twice (sqlalchemy 0.7.4 with oracle)

2012-01-23 Thread Robert Forkel
hi, just ran into the following problem: When creating tables (for oracle) with a primary key fetched from a sequence, the create statement for the sequence is issued twice; i.e. the following code from sqlalchemy import MetaData, create_engine, Table, Column, Integer, Sequence from sqlalchemy.sch

Re: [sqlalchemy] SqlAlchemy dynamic query generation

2011-12-22 Thread Robert Forkel
ns)).all() might do the trick (untested). On Thu, Dec 22, 2011 at 9:53 AM, Sana klh wrote: > Hi Robert Forkel, > > You got it right i am trying to have a combination of expression combined in > and_. > > I need to add the attribute only when it is not equal to null.So i tried to > c

Re: [sqlalchemy] SqlAlchemy dynamic query generation

2011-12-21 Thread Robert Forkel
You may want to look at the tutorial [1]. In the code you pasted you are assembling a string to pass to filter. While you can do that (but then it should be proper sql not python!), what you want to do is passing a python expression like db.User.age==age, or a combination of expressions combined us

[sqlalchemy] bug in reflection.py sqla 0.7.3

2011-11-30 Thread Robert Forkel
Hi, trying to use Inspector.get_table_names with order_by='foreign_key' causes the following exception: Traceback (most recent call last): File "db_inspector.py", line 20, in for table in insp.get_table_names(schema=schema, order_by='foreign_key'): File "lib/python2.6/site-packages/sqlalc

Re: [sqlalchemy] Column Mixin

2011-11-27 Thread Robert Forkel
Hi, I'm doing something similar and ended up giving all columns contributed by a mixin a common prefix, and have the copy method loop over all columns of an object, picking out the right ones. Regards Robert Am 26.11.2011 15:26 schrieb "Mark Erbaugh" : > I'm using a ColumnMixin to have a subset o

Re: [sqlalchemy] Re: howto Sqlalchemy atomic transaction ??

2011-11-21 Thread Robert Forkel
DBSession.flush() after the DBSession.add call might be enough. On Mon, Nov 21, 2011 at 12:48 PM, sajuptpm wrote: > Model > > class VDCTemplates(DeclarativeBase): >    __tablename__='cd_vdc_templates' >    id = Column(Unicode(50), primary_key=True) >    vdc_id=Column(Unicode(50), Forei

Re: [sqlalchemy] exists for query

2011-11-18 Thread Robert Forkel
query.first() may do the trick. Regards Robert Am 18.11.2011 15:25 schrieb "lestat" : > > I often pass db query in template context, and in template I check if > it exists, that render one html block, else other html block. > > Can I in sqlalchemy check existance of query? > > Now I simply call q

Re: [sqlalchemy] Determine column properties created via declarative mixins

2011-10-17 Thread Robert Forkel
.7.2' Anyway, your hint solved my problem, thanx! regards robert On Mon, Oct 17, 2011 at 7:10 PM, Michael Bayer wrote: > > On Oct 17, 2011, at 5:40 AM, Robert Forkel wrote: > >> Hi all, >> Using sqlalchemy 0.7.2 I created a couple of mixin classes (say Mixin) >> to s

[sqlalchemy] Determine column properties created via declarative mixins

2011-10-17 Thread Robert Forkel
Hi all, Using sqlalchemy 0.7.2 I created a couple of mixin classes (say Mixin) to share columns declarations between model classes (say A and B). Sometimes I have to create instances of type B initialized with the values of an existing object of type A for the columns declared by Mixin. I'd like to