[sqlalchemy] Re: Flask - SQLAlchemy - Error when insert a GUID as primary key

2016-03-21 Thread Ricardo Champa
I forget post the error message: I'm getting an error after perform an insert statement. class Tag(db.Model): __tablename__ = "tags" guid_tag = db.Column(db.BINARY(16), primary_key=True) id_project = db.Column(db.Integer,db.ForeignKey("projects.id_project")) project =

[sqlalchemy] Flask - SQLAlchemy - Error when insert a GUID as primary key

2016-03-21 Thread Ricardo Champa
I'm getting an error after perform an insert statement. class Tag(db.Model): __tablename__ = "tags" guid_tag = db.Column(db.BINARY(16), primary_key=True) id_project = db.Column(db.Integer,db.ForeignKey("projects.id_project")) project = db.relationship(Proyecto,

Re: [sqlalchemy] Re: order by child object's field

2016-03-21 Thread c.buhtz
Dear Simon, thanks. This works and look great. I should stick this code on my sleeping pillow. :D >From viewpoint of SQL or the database this makes totally sense to me. But my fault (in thinking) was expect that the relationship() definitions I did in the classes would be enough for SQLA to know

Re: [sqlalchemy] Re: order by child object's field

2016-03-21 Thread Simon King
On Mon, Mar 21, 2016 at 5:21 PM, wrote: > Hi Michal > > > q.join(ReferenceAuthor, ReferenceAuthor.c.Index == 0) > > Ah, of course! Thank you very much! > > But... ;) > > This Python code > > return self.session.query(Reference) \ >

Re: [sqlalchemy] Re: order by child object's field

2016-03-21 Thread c.buhtz
Hi Michal > q.join(ReferenceAuthor, ReferenceAuthor.c.Index == 0) Ah, of course! Thank you very much! But... ;) This Python code return self.session.query(Reference) \ .filter_by(_mark = False) \ .join(Periodical) \

Re: [sqlalchemy] Re: order by child object's field

2016-03-21 Thread Michal Petrucha
On Mon, Mar 21, 2016 at 05:21:21PM +0100, c.bu...@posteo.jp wrote: > > ReferenceAuthor is an instance of sqlalchemy.Table, so you can refer > > to its columns as ReferenceAuthor.c.Index. > > Ah nice. But something is still wrong. > Part of the query: > > .join(ReferenceAuthor, >

Re: [sqlalchemy] Re: order by child object's field

2016-03-21 Thread c.buhtz
> ReferenceAuthor is an instance of sqlalchemy.Table, so you can refer > to its columns as ReferenceAuthor.c.Index. Ah nice. But something is still wrong. Part of the query: .join(ReferenceAuthor, ReferenceAuthor.c.Index=0) \ result in ReferenceAuthor.c.Index=0) \

Re: [sqlalchemy] Modeling single FK to multiple tables

2016-03-21 Thread Simon King
Can you extract your code into a single standalone script that demonstrates the problem? This should be possible even with automap; the script can start by creating just the tables that are involved in this problem (ideally in an in-memory sqlite db), then use automap to map classes to those

Re: [sqlalchemy] Re: order by child object's field

2016-03-21 Thread Simon King
On Mon, Mar 21, 2016 at 3:05 PM, wrote: > On 2016-03-20 13:12 Jonathan Vanasco wrote: > > .contains_eager('_periodical')\ # this lets sqlalchemy > > This eager-loading thing is a nice hint. I will use this in the future. > Thanks. > > I

Re: [sqlalchemy] Modeling single FK to multiple tables

2016-03-21 Thread Alex Hall
Wow, thanks guys, especially for the sample code! I'm trying to use the example (and fully understand it at the same time) but am running into an error. This is the same error that made me look for a way other than this last week. sqlalchemy.exc.InvalidRequestError: when initializing mapper

Re: [sqlalchemy] Re: order by child object's field

2016-03-21 Thread c.buhtz
On 2016-03-20 13:12 Jonathan Vanasco wrote: > .contains_eager('_periodical')\ # this lets sqlalchemy This eager-loading thing is a nice hint. I will use this in the future. Thanks. I haven't specified a important part of my question because I didn't think about

Re: [sqlalchemy] rowset generating functions in FROM clause

2016-03-21 Thread Mike Bayer
for the "postgresql JSON function that wants to be in the FROM clause", there is a way to do this with plain Core API but it generates a subquery (that's here: http://docs.sqlalchemy.org/en/rel_1_0/core/tutorial.html#functions , scroll down a little in that section), but also I've been

[sqlalchemy] rowset generating functions in FROM clause

2016-03-21 Thread Andy S
I'm stuck with the need to generate a query of the form like: SELECT a.id, b.name, jr.* FROM a, b outer join jsonb_populate_recordset(b.jrs) as jr(bid numeric, name varchar) on (TRUE) WHERE a.id = b.a_id First, it's not clear to me how to construct a dynamically defined RECORD as 'jr(bid