Great! That worked, though I had to add server_default=FetchedValue()
and server_onupdate=FetchedValue().
Would be nice if SQLAlchemy auto-detected this case, but no big deal
otherwise.


Thanks!

Jack

On Tue, Apr 28, 2015 at 4:42 PM Mike Bayer <[email protected]> wrote:

>  use the eager_defaults flag:
>
>
>
> http://docs.sqlalchemy.org/en/rel_1_0/orm/mapping_api.html?highlight=eager_defaults#sqlalchemy.orm.mapper.params.eager_defaults
>
>
> http://docs.sqlalchemy.org/en/rel_0_9/changelog/migration_09.html#orm-can-efficiently-fetch-just-generated-insert-update-defaults-using-returning
>
>
> not sure if this works for the ad-hoc set up updated_at, try it out.   if
> it's a server_default on the Column, should definitely work.
>
>
>
>
>
> On 4/28/15 7:35 PM, univerio wrote:
>
> Suppose I have a PostgreSQL backend and I have the following class:
>
>      class Foo(Base):
>         id = Column(Integer, primary_key=True)
>         updated_at = Column(DateTime)
>
>  and I do
>
>      foo = Foo(updated_at=func.now())
>     session.add(foo)
>     session.flush()
>     foo.id  # this is already loaded, no additional query emitted
>     foo.updated_at  # this is not loaded, will cause an additional query
> to be emitted
>
>  Is it possible to have the SQLAlchemy ORM fetch the actual value of
> updated_at as part of the INSERT...RETURNING statement like it does for id,
> instead of leaving it unloaded and having to issue a second query when I
> access it?
>
>
>  Jack
>  --
>
> 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 [email protected].
>
>
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "sqlalchemy" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/sqlalchemy/F2QKToSNKKM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to