[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 = db.relationship(Proyecto, backref=db.backref('list_tags', 
lazy='dynamic'))
type= db.Column(db.Integer) 
#(0,hub);(1,cable);(2,pipe);(3,electrical_pipes)
created_at  = db.Column(db.DateTime)
updated_at  = db.Column(db.DateTime)

def __init__(self,guid_tag,project,type,created_at):
self.guid_tag = guid_tag
self.project = project
self.type = type
self.created_at = created_at
self.updated_at = created_at

Insert statement

guid_tag= func.UNHEX(args['guid_tag'])
nuevo_tag = Tag(guid_tag,id_project,type,creado_en)
db.session.add(nuevo_tag)
db.session.commit()

The message error

File 
"/Users/Ricardo/PycharmProjects/virtual_rfwire/lib/python3.3/site-packages/sqlalchemy/orm/loading.py",
 
line 647, in load_scalar_attributes "contain a full primary key." % 
state_str(state)) sqlalchemy.exc.InvalidRequestError: Instance cannot be 
refreshed - it's not persistent and does not contain a full primary key.


El martes, 22 de marzo de 2016, 6:05:44 (UTC+1), Ricardo Champa escribió:
>
> 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, backref=db.backref('list_tags', 
> lazy='dynamic'))
> type= db.Column(db.Integer) 
> #(0,hub);(1,cable);(2,pipe);(3,electrical_pipes)
> created_at  = db.Column(db.DateTime)
> updated_at  = db.Column(db.DateTime)
>
> def __init__(self,guid_tag,project,type,created_at):
> self.guid_tag = guid_tag
> self.project = project
> self.type = type
> self.created_at = created_at
> self.updated_at = created_at
>
> Insert statement
>
> guid_tag= func.UNHEX(args['guid_tag'])
> nuevo_tag = Tag(guid_tag,id_project,type,creado_en)
> db.session.add(nuevo_tag)
> db.session.commit()
>
>

-- 
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 this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[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, backref=db.backref('list_tags', 
lazy='dynamic'))
type= db.Column(db.Integer) 
#(0,hub);(1,cable);(2,pipe);(3,electrical_pipes)
created_at  = db.Column(db.DateTime)
updated_at  = db.Column(db.DateTime)

def __init__(self,guid_tag,project,type,created_at):
self.guid_tag = guid_tag
self.project = project
self.type = type
self.created_at = created_at
self.updated_at = created_at

Insert statement

guid_tag= func.UNHEX(args['guid_tag'])
nuevo_tag = Tag(guid_tag,id_project,type,creado_en)
db.session.add(nuevo_tag)
db.session.commit()

-- 
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 this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


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 what
I want. ;)
I should never keep SQL out of my head.

This will help me a lot in the future!

-- 
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 this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


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) \
>  .filter_by(_mark = False) \
>  .join(Periodical) \
>  .join(ReferenceAuthor,
>ReferenceAuthor.c.Index==0) \
>  .join(Person) \
>  .order_by(Periodical._name) \
>  .order_by(Person._lastname) \
>  .all()
>
>
>
> The SQL echoed looks ok:
>
> SELECT "Reference"."ID" AS "Reference_ID",
>"Reference"."HasLabel" AS "Reference_HasLabel",
>"Reference"."PeriodicalID" AS "Reference_PeriodicalID"
> FROM "Reference"
> JOIN "Periodical"
> ON "Periodical"."ID" = "Reference"."PeriodicalID"
> JOIN "ReferenceAuthor"
> ON "ReferenceAuthor"."Index" = ?
> JOIN "Person"
> ON "Person"."ID" = "ReferenceAuthor"."PersonID"
> WHERE "Reference"."HasLabel" = 0
> ORDER BY "Periodical"."Name",
>  "Person"."LastName"
>
> But result doesn't looks like that it is secondary sorted by first
> persons lastname. See as an example one "Periodical._name" (Bmc
> Geriatrics) and the first persons lastname of 8 References.
>
> Bmc Geriatrics
>   Dapp
>   Tuntland
>   Hsu
>   van der Elst
>   Khatib
>   Hermans
>   van Buul
>   Lichtner
>

You are missing the join condition between ReferenceAuthor and Reference.
You probably want something like this:

join(ReferenceAuthor,
 and_(ReferenceAuthor.c.ReferenceId == Reference.ID),
  ReferenceAuthor.c.Index == 0))

Simon

-- 
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 this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


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) \
 .join(ReferenceAuthor,
   ReferenceAuthor.c.Index==0) \
 .join(Person) \
 .order_by(Periodical._name) \
 .order_by(Person._lastname) \
 .all()



The SQL echoed looks ok:

SELECT "Reference"."ID" AS "Reference_ID",
   "Reference"."HasLabel" AS "Reference_HasLabel",
   "Reference"."PeriodicalID" AS "Reference_PeriodicalID"
FROM "Reference"
JOIN "Periodical"
ON "Periodical"."ID" = "Reference"."PeriodicalID"
JOIN "ReferenceAuthor"
ON "ReferenceAuthor"."Index" = ?
JOIN "Person"
ON "Person"."ID" = "ReferenceAuthor"."PersonID"
WHERE "Reference"."HasLabel" = 0
ORDER BY "Periodical"."Name",
 "Person"."LastName"

But result doesn't looks like that it is secondary sorted by first
persons lastname. See as an example one "Periodical._name" (Bmc
Geriatrics) and the first persons lastname of 8 References.

Bmc Geriatrics
  Dapp
  Tuntland
  Hsu
  van der Elst
  Khatib
  Hermans
  van Buul
  Lichtner

-- 
Verfassungsbeschwerden gegen Vorratsdatenspeicherung

Dein Recht zu unterzeichnen!

-- 
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 this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


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,
>   ReferenceAuthor.c.Index=0) \
> 
> result in
> ReferenceAuthor.c.Index=0) \
> ^
> 
> SyntaxError: keyword can't be an expression
> 
> Not sure what is wrong here. But I think c.Index doesn't exist?

That's not it, try:

q.join(ReferenceAuthor, ReferenceAuthor.c.Index == 0)

If you use a single equals sign, Python understands that as an attempt
to use a keyword argument; keyword arguments need to be valid Python
identifiers, not arbitrary expressions. That's why it gave you a
SyntaxError.

In this case, you do not want to use a keyword argument, but an
ordinary expression that gets translated into SQL by SQLAlchemy.

Good luck,

Michal

-- 
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 this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


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) \
^

SyntaxError: keyword can't be an expression

Not sure what is wrong here. But I think c.Index doesn't exist?

-- 
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 this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


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 tables.

Simon

On Mon, Mar 21, 2016 at 3:12 PM, Alex Hall  wrote:

> 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
> Mapper|assignmentTable|assignment, expression 'item' failed to to
> locate an item (name 'item' is not defined). If this is a class name,
> consider adding this relationship() to the
>  class after both dependent classes
> have been defined.
>
> This all starts from the line where my query begins:
>
> items = session.query(itemTable)\
>
> Again, I'm using automap. I put the class definitions in the same
> place I put my vendor table definition last week, where it worked
> perfectly. That's just after I set
> base = automap_base()
> but before I reflect anything. I can paste the full code if you want,
> but it's pretty long.
>
> On 3/17/16, Mike Bayer  wrote:
> >
> >
> > On 03/17/2016 03:11 PM, Alex Hall wrote:
> >> Hello all,
> >> It seems like I can't go a day without running into some kind of wall.
> >> This one is a conceptual one regarding foreign keys. I have to somehow
> >> get the same FK column in table A pointing to IDs in tables B and C.
> >
> > So a real foreign key constraint is not capable of this.  Repurposing a
> > single column to occasionally point to one table or another is a famous
> > anti-pattern I've spoke of much (warning, this is *extremely* old, but
> > the general idea still holds):
> >
> >
> http://techspot.zzzeek.org/2007/05/29/polymorphic-associations-with-sqlalchemy/
> >
> >
> > I have an updated version of all the various "polymoprhic association"
> > examples in SQLAlchemy itself at
> >
> http://docs.sqlalchemy.org/en/rel_1_0/orm/examples.html#module-examples.generic_associations
> .
> >
> >   This includes the "single column pointing to multiple tables" hack, as
> > well as three other versions of the same business object geometry which
> > preserve relational integrity within the schema design.
> >
> >>
> >> At one person's suggestion, I'm making classes for my tables, even
> >> though I'm using automap. This is to let me stop doing a ton of joins,
> >> making querying much easier... I hope! I'm defining all the foreign
> >> keys between my tables manually. For instance:
> >>
> >> class item(base):
> >>   __tablename__ = "item"
> >>   itm_id = Column(Integer, primary_key=True)
> >>   vendornum = Column(String, ForeignKey(VENDR.PVVNNO))
> >>
> >> class vendorTable(base):
> >>   __tablename__ = "VENDR"
> >>   PVVNNO = Column(String, primary_key=True)
> >>
> >> If I've understood correctly, I'll now be able to say
> >> item.vendornum.vendor_full_name
> >> to get the vendor's full name for any item.
> >>
> >> Here's the problem. Items have attachments, and attached text,
> >> respectively held in attach and attach_text tables. Binding them to
> >> items is a table called assignment. Assignment is pretty
> >> straightforward, with an itm_id and an attachment id (att_id). The
> >> trouble is that this att_id occurs in both attach and attach_text. I
> >> can make att_id a foreign key to one table or the other, but I'm not
> >> sure how to make it go to both tables.
> >
> > the "generic_fk" example illustrates a pattern for working with this.
> >
> > Getting this all to work with automap is another layer of complexity,
> > you certainly want all of this part of it laid out before you reflect
> > the rest of the database columns.
> >
> >
> >>
> >> class assignmentTable(base):
> >>   __tablename__ = "assignment"
> >>   itm_id = Column(Integer, ForeignKey(item.itm_id))
> >>   #the following column has to point to attach_text.att_id AS WELL
> >>att_id = Column(Integer, ForeignKey(attachment.att_id))
> >>   seq_num = Column(Integer)
> >>   asn_primary = Column(Integer, nullable=True)
> >>
> >> class attachmentTable(base):
> >>   __tablename__ = "attachment"
> >>   att_id = Column(Integer, primary_key=True)
> >>
> >> class attachmentTextTable(base):
> >>   __tablename__ = "attach_text"
> >>   att_id = Column(Integer, primary_key=True)
> >>
> >
> > --
> > 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 this group, send email to sqlalchemy@googlegroups.com.
> > Visit this group at https://groups.google.com/group/sqlalchemy.
> > For more options, visit https://groups.google.com/d/optout.
> >

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 haven't specified a important part of my question because I didn't
> think about it. :)
>
> A "Reference" can have more then one "Persons" (relation is
> "ReferenceAuthor"). The "Persons" are orderd by an index
> ("ReferenceAuthor."Index").
> How can I order by "Person._lastname" of only the FRIST author? I could
> write something like this
>
>   join(ReferenceAuthor, ReferenceAuthor.Index=0)
>
> But my problem is that I don't know how to name/adress this index
> field? As you can see in my first post this column doesn't have a
> "name" (in pythonic meaning). It is just a Column("Index", ...).
>

ReferenceAuthor is an instance of sqlalchemy.Table, so you can refer to its
columns as ReferenceAuthor.c.Index.

Simon

-- 
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 this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


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
Mapper|assignmentTable|assignment, expression 'item' failed to to
locate an item (name 'item' is not defined). If this is a class name,
consider adding this relationship() to the
 class after both dependent classes
have been defined.

This all starts from the line where my query begins:

items = session.query(itemTable)\

Again, I'm using automap. I put the class definitions in the same
place I put my vendor table definition last week, where it worked
perfectly. That's just after I set
base = automap_base()
but before I reflect anything. I can paste the full code if you want,
but it's pretty long.

On 3/17/16, Mike Bayer  wrote:
>
>
> On 03/17/2016 03:11 PM, Alex Hall wrote:
>> Hello all,
>> It seems like I can't go a day without running into some kind of wall.
>> This one is a conceptual one regarding foreign keys. I have to somehow
>> get the same FK column in table A pointing to IDs in tables B and C.
>
> So a real foreign key constraint is not capable of this.  Repurposing a
> single column to occasionally point to one table or another is a famous
> anti-pattern I've spoke of much (warning, this is *extremely* old, but
> the general idea still holds):
>
> http://techspot.zzzeek.org/2007/05/29/polymorphic-associations-with-sqlalchemy/
>
>
> I have an updated version of all the various "polymoprhic association"
> examples in SQLAlchemy itself at
> http://docs.sqlalchemy.org/en/rel_1_0/orm/examples.html#module-examples.generic_associations.
>
>   This includes the "single column pointing to multiple tables" hack, as
> well as three other versions of the same business object geometry which
> preserve relational integrity within the schema design.
>
>>
>> At one person's suggestion, I'm making classes for my tables, even
>> though I'm using automap. This is to let me stop doing a ton of joins,
>> making querying much easier... I hope! I'm defining all the foreign
>> keys between my tables manually. For instance:
>>
>> class item(base):
>>   __tablename__ = "item"
>>   itm_id = Column(Integer, primary_key=True)
>>   vendornum = Column(String, ForeignKey(VENDR.PVVNNO))
>>
>> class vendorTable(base):
>>   __tablename__ = "VENDR"
>>   PVVNNO = Column(String, primary_key=True)
>>
>> If I've understood correctly, I'll now be able to say
>> item.vendornum.vendor_full_name
>> to get the vendor's full name for any item.
>>
>> Here's the problem. Items have attachments, and attached text,
>> respectively held in attach and attach_text tables. Binding them to
>> items is a table called assignment. Assignment is pretty
>> straightforward, with an itm_id and an attachment id (att_id). The
>> trouble is that this att_id occurs in both attach and attach_text. I
>> can make att_id a foreign key to one table or the other, but I'm not
>> sure how to make it go to both tables.
>
> the "generic_fk" example illustrates a pattern for working with this.
>
> Getting this all to work with automap is another layer of complexity,
> you certainly want all of this part of it laid out before you reflect
> the rest of the database columns.
>
>
>>
>> class assignmentTable(base):
>>   __tablename__ = "assignment"
>>   itm_id = Column(Integer, ForeignKey(item.itm_id))
>>   #the following column has to point to attach_text.att_id AS WELL
>>att_id = Column(Integer, ForeignKey(attachment.att_id))
>>   seq_num = Column(Integer)
>>   asn_primary = Column(Integer, nullable=True)
>>
>> class attachmentTable(base):
>>   __tablename__ = "attachment"
>>   att_id = Column(Integer, primary_key=True)
>>
>> class attachmentTextTable(base):
>>   __tablename__ = "attach_text"
>>   att_id = Column(Integer, primary_key=True)
>>
>
> --
> 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 this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


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 it. :)

A "Reference" can have more then one "Persons" (relation is
"ReferenceAuthor"). The "Persons" are orderd by an index
("ReferenceAuthor."Index").
How can I order by "Person._lastname" of only the FRIST author? I could
write something like this

  join(ReferenceAuthor, ReferenceAuthor.Index=0)

But my problem is that I don't know how to name/adress this index
field? As you can see in my first post this column doesn't have a
"name" (in pythonic meaning). It is just a Column("Index", ...).

-- 
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 this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


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 pointing 
people to an interim solution that has all of PG's functions in mind, 
that is here: 
https://bitbucket.org/zzzeek/sqlalchemy/issues/3566/figure-out-how-to-support-all-of-pgs#comment-22842678 
.It includes two examples to get you started.


On 03/21/2016 06:38 AM, Andy S wrote:

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)asjr(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 numeric, name varchar)' so 'jr' becomes a table name
that could be referenced later on

Then it's not clear to me how to construct a table-like object of a
function call that one can reference in query() by it's name ('jr' in
this case).


Is it possible with SQLAlchemy?

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


[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 numeric, name varchar)' so 'jr' becomes a table name that could 
be referenced later on

Then it's not clear to me how to construct a table-like object of a 
function call that one can reference in query() by it's name ('jr' in this 
case).


Is it possible with SQLAlchemy?

-- 
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 this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.