I've posted the answer on StackOverflow. You have client_encoding =
sql_ascii in your postgresql.conf, and you just need to change that to utf8
or override it in your create_engine call.
Cheers,
Gulli
On Wed, Jul 23, 2014 at 6:59 PM, Michael Bayer mike...@zzzcomputing.com
wrote:
On Jul 23,
Hi Pavel,
You want: s.query(Person).with_polymorphic(Man).get(51)
Cheers,
Gulli
On Tue, Apr 15, 2014 at 12:59 PM, Pavel Aborilov abori...@gmail.com wrote:
Hello!
How can I cache query like this:
session.query(Person).get(51)
where 51 is id of Man
I can't access attribute age of Man
On Tue, Apr 15, 2014 at 1:11 PM, Pavel Aborilov abori...@gmail.com wrote:
but I dont know on the time of query what the type of object it will be.
Then you can use session.query(Person).with_polymorphic('*') to mean
joining to the tables of all mapped subclasses. (Be aware that this can
become
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 some
It means that an object in memory (or some of its attributes), representing
an entity in the DB, is no longer considered to reflect the state of that
entity accurately because the entity may have changed in the DB. So next
time attributes are read from the object, fresh DB state is queried. See
Hi,
read the section Session
Attributeshttp://docs.sqlalchemy.org/en/latest/orm/session.html#sqlalchemy.orm.session.Session.identity_map.
You
might just need something like len(session.identity_map) + len(session.new)
... but there are some caveats, involving exactly what you mean by the
session
Hi,
1. the server_default=... argument just says what default to define for the
column *on creation* --- it has no effect if the table already exists. To
apply the default to an existing table, you need to execute something like:
ALTER TABLE mytbl ALTER COLUMN mycol ADD DEFAULT
There is something for this in SQLAlchemy-Utils, I noticed the other day:
http://sqlalchemy-utils.readthedocs.org/en/latest/data_types.html#module-sqlalchemy_utils.types.json
... but I have no idea how useful or mature that is.
Gulli
On Mon, Nov 18, 2013 at 3:24 PM, Michael Bayer
The reason for the extra selects is that calling commit() marks objects in
the session as expired, so they need to be refreshed. From the ORM
tutorialhttp://docs.sqlalchemy.org/en/rel_0_8/orm/tutorial.html
:
SQLAlchemy by default refreshes data from a previous transaction the first
time it’s
Oh, that's what it is. The override of the addition + operator by the
concatenation operator || only happens if the right-hand side type is also
a “concatenable” or NULL, not just the left side:
https://github.com/zzzeek/sqlalchemy/blob/rel_0_8_2/lib/sqlalchemy/types.py#L1017-L1023
and integer
I would have expected the SQLite dialect to know how to compile concat
to ||if that's the operator. But failing that, something more explicit
like this
ought to do the trick:
from sqlalchemy.sql import literal_column
literal_column('+ ').op('||')(seconds.c.n).op('||')(literal_column('
seconds'))
To clarify:
- The class-level attribute Member.dateofbirth is not a date/datetime
object. It is a instrumented attribute representing a column in the
database table behind this model. So it does not have any method called
replace.
- Once you get an *instance* of Member, the instance-level
sorry, it looks like the OP did want people born on the current
month/day/year combo.
No, you were right the first time : ) ... he wanted members whose
dateofbirth, *after changing the year to the current year*, would be today.
That amounts to equating the month and day only.
Something like
Yep: object_session(obj)
http://docs.sqlalchemy.org/en/rel_0_8/orm/session.html#sqlalchemy.orm.session.Session.object_session
Regards,
Gulli
On Thu, May 2, 2013 at 4:47 PM, Jonathan Vanasco jonat...@findmeon.comwrote:
i'm trying to deal with some old code , and need to 'log' a change. in
On Thu, May 2, 2013 at 5:08 PM, Michael Bayer mike...@zzzcomputing.comwrote:
and in 0.8 its this:
from sqlalchemy import inspect
session = inspect(obj).session
Is this preferred over object_session in 0.8? object_session is still
there, and docs don't say it's deprecated or that
No, the comma is supposed to be there; it's for tuple unpacking. The
iterable q yields tuples (which in this case are of length one, because the
resultset has only one column).
The column should be whatever attribute of the ORM instances you want to
sort by, not necessarily the primary key.
The
OK, so it's the database driver that should make sure values suit the
columns they are bound to, but @validates allows me to do it too. Makes
perfect sense — thanks!
Regards,
- Gulli
On Thu, Mar 12, 2009 at 2:28 PM, Michael Bayer mike...@zzzcomputing.comwrote:
Gunnlaugur Briem wrote:
See:
http://www.sqlalchemy.org/docs/05/reference/orm/sessions.html#sqlalchemy.orm.create_session
“The defaults of create_session() are the opposite of that of
sessionmaker(); autoflush and expire_on_commit are False, autocommit is
True. [...] It is recommended to use sessionmaker() instead of
The context of the infinite recursion is this:
def __getattr__(self, attribute):
Delegate __getattr__ to the original descriptor and/or
comparator.
try:
return getattr(descriptor, attribute)
except AttributeError:
try:
approach
looping on columns i append it in to the table and hence making the
object
i can join them with operator to form the a+b-c but in this a b c
becomes string which is not desirable i want object here
i hope this will clear the picture
On Feb 25, 6:40 pm, Gunnlaugur Thor Briem
Thanks. But using a CASE clause becomes objectionable in exactly those cases
where I would want to have the DB do the sorting — i.e. where the table is
big enough that just sorting the result set in python code using array index
(rows.sort(key=lambda row: values.index(row[0]))) would be a Bad
))
e = create_engine('sqlite:///:memory:')
e.execute(t.insert(), [{'a':1, 'b':2, 'c':4}])
e.execute(select([sum(t.c)])).fetchall() # equiv. to SELECT a+b+c FROM t
# [(7,)]
Regards,
- Gulli
On Wed, Feb 25, 2009 at 1:40 PM, Gunnlaugur Thor Briem gunnlau...@gmail.com
wrote:
You can sum
Works for me (once I add metadata.create_all(bind=engine) ) ... possibly you
have an old SQLite that doesn't do the auto-incrementing primary key thing?
- G.
On Wed, Feb 18, 2009 at 2:26 PM, Marcin Krol mrk...@gmail.com wrote:
Hello,
I just started learning sqlalchemy, my version is
Hi,
[trying to send this again, seems like previous copy got lost in some
moderation queue]
Messing with single-table inheritance in a declarative model, with a
non-abstract base class, I find that querying fails if polymorphic_identity
is 0 (zero). Example:
code begins
24 matches
Mail list logo