Re: [sqlalchemy] Determining what, if anything, a Session.merge() does?

2016-03-10 Thread Russ
Excellent, thank you.  is_modified() works very well in this case, with 
caveats noted.  Also, a nice intro to the History API... hadn't seen that 
before!

-- 
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] Error dropping table with sequence on Postgres

2016-03-10 Thread Mike Bayer



On 03/10/2016 09:52 PM, Jay Camp wrote:

Postgres: 9.4
SQLAlchemy: 1.0.11

When a sequence is created against a column, calling
`metadata.drop_all()` tries to drop the sequence before dropping the
table and fails because the table is still referencing the sequence.
Manually dropping the table then dropping the sequence works.

The test script is attached. Here is the console output:

2016-03-10 18:44:27,101 INFO sqlalchemy.engine.base.Engine select version()
2016-03-10 18:44:27,101 INFO sqlalchemy.engine.base.Engine {}
2016-03-10 18:44:27,104 INFO sqlalchemy.engine.base.Engine select
current_schema()
2016-03-10 18:44:27,104 INFO sqlalchemy.engine.base.Engine {}
2016-03-10 18:44:27,106 INFO sqlalchemy.engine.base.Engine SELECT
CAST('test plain returns' AS VARCHAR(60)) AS anon_1
2016-03-10 18:44:27,106 INFO sqlalchemy.engine.base.Engine {}
2016-03-10 18:44:27,109 INFO sqlalchemy.engine.base.Engine SELECT
CAST('test unicode returns' AS VARCHAR(60)) AS anon_1
2016-03-10 18:44:27,109 INFO sqlalchemy.engine.base.Engine {}
2016-03-10 18:44:27,110 INFO sqlalchemy.engine.base.Engine show
standard_conforming_strings
2016-03-10 18:44:27,110 INFO sqlalchemy.engine.base.Engine {}
2016-03-10 18:44:27,111 INFO sqlalchemy.engine.base.Engine select
relname from pg_class c join pg_namespace n on n.oid=c.relnamespace
where pg_catalog.pg_table_is_visible(c.oid) and relname=%(name)s
2016-03-10 18:44:27,112 INFO sqlalchemy.engine.base.Engine {'name':
u'drop_seq_test'}
2016-03-10 18:44:27,115 INFO sqlalchemy.engine.base.Engine SELECT
relname FROM pg_class c join pg_namespace n on n.oid=c.relnamespace
where relkind='S' and n.nspname=current_schema() and relname=%(name)s
2016-03-10 18:44:27,115 INFO sqlalchemy.engine.base.Engine {'name':
u'drop_seq_col'}
2016-03-10 18:44:27,117 INFO sqlalchemy.engine.base.Engine CREATE
SEQUENCE drop_seq_col
2016-03-10 18:44:27,117 INFO sqlalchemy.engine.base.Engine {}
2016-03-10 18:44:27,127 INFO sqlalchemy.engine.base.Engine COMMIT
2016-03-10 18:44:27,129 INFO sqlalchemy.engine.base.Engine
CREATE TABLE drop_seq_test (
col INTEGER DEFAULT nextval('drop_seq_col') NOT NULL,
source_id SERIAL NOT NULL,
PRIMARY KEY (source_id),
UNIQUE (col)
)


2016-03-10 18:44:27,129 INFO sqlalchemy.engine.base.Engine {}
2016-03-10 18:44:27,147 INFO sqlalchemy.engine.base.Engine COMMIT
2016-03-10 18:44:27,148 INFO sqlalchemy.engine.base.Engine select
relname from pg_class c join pg_namespace n on n.oid=c.relnamespace
where pg_catalog.pg_table_is_visible(c.oid) and relname=%(name)s
2016-03-10 18:44:27,148 INFO sqlalchemy.engine.base.Engine {'name':
u'drop_seq_test'}
2016-03-10 18:44:27,150 INFO sqlalchemy.engine.base.Engine SELECT
relname FROM pg_class c join pg_namespace n on n.oid=c.relnamespace
where relkind='S' and n.nspname=current_schema() and relname=%(name)s
2016-03-10 18:44:27,150 INFO sqlalchemy.engine.base.Engine {'name':
u'drop_seq_col'}
2016-03-10 18:44:27,151 INFO sqlalchemy.engine.base.Engine DROP SEQUENCE
drop_seq_col
2016-03-10 18:44:27,151 INFO sqlalchemy.engine.base.Engine {}
2016-03-10 18:44:27,152 INFO sqlalchemy.engine.base.Engine ROLLBACK
Traceback (most recent call last):
   File "drop-sequence.py", line 17, in 
 metadata.drop_all()
   File
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/sql/schema.py",
line 3722, in drop_all
 tables=tables)
   File
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 1856, in _run_visitor
 conn._run_visitor(visitorcallable, element, **kwargs)
   File
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 1481, in _run_visitor
 **kwargs).traverse_single(element)
   File
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/sql/visitors.py",
line 121, in traverse_single
 return meth(obj, **kw)
   File
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/sql/ddl.py",
line 871, in visit_metadata
 table, drop_ok=True, _is_metadata_operation=True)
   File
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/sql/visitors.py",
line 121, in traverse_single
 return meth(obj, **kw)
   File
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/sql/ddl.py",
line 916, in visit_table
 self.traverse_single(column.default)
   File
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/sql/visitors.py",
line 121, in traverse_single
 return meth(obj, **kw)
   File
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/sql/ddl.py",
line 934, in visit_sequence
 self.connection.execute(DropSequence(sequence))
   File
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 914, in execute
 return meth(self, multiparams, params)
   File
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/sql/ddl.py",
line 68, in _execute_on_connection
 return connection._execute_ddl(self, multiparams, params

[sqlalchemy] Error dropping table with sequence on Postgres

2016-03-10 Thread Jay Camp
Postgres: 9.4
SQLAlchemy: 1.0.11

When a sequence is created against a column, calling `metadata.drop_all()` 
tries to drop the sequence before dropping the table and fails because the 
table is still referencing the sequence. Manually dropping the table then 
dropping the sequence works.

The test script is attached. Here is the console output:

2016-03-10 18:44:27,101 INFO sqlalchemy.engine.base.Engine select version()
2016-03-10 18:44:27,101 INFO sqlalchemy.engine.base.Engine {}
2016-03-10 18:44:27,104 INFO sqlalchemy.engine.base.Engine select 
current_schema()
2016-03-10 18:44:27,104 INFO sqlalchemy.engine.base.Engine {}
2016-03-10 18:44:27,106 INFO sqlalchemy.engine.base.Engine SELECT 
CAST('test plain returns' AS VARCHAR(60)) AS anon_1
2016-03-10 18:44:27,106 INFO sqlalchemy.engine.base.Engine {}
2016-03-10 18:44:27,109 INFO sqlalchemy.engine.base.Engine SELECT 
CAST('test unicode returns' AS VARCHAR(60)) AS anon_1
2016-03-10 18:44:27,109 INFO sqlalchemy.engine.base.Engine {}
2016-03-10 18:44:27,110 INFO sqlalchemy.engine.base.Engine show 
standard_conforming_strings
2016-03-10 18:44:27,110 INFO sqlalchemy.engine.base.Engine {}
2016-03-10 18:44:27,111 INFO sqlalchemy.engine.base.Engine select relname 
from pg_class c join pg_namespace n on n.oid=c.relnamespace where 
pg_catalog.pg_table_is_visible(c.oid) and relname=%(name)s
2016-03-10 18:44:27,112 INFO sqlalchemy.engine.base.Engine {'name': 
u'drop_seq_test'}
2016-03-10 18:44:27,115 INFO sqlalchemy.engine.base.Engine SELECT relname 
FROM pg_class c join pg_namespace n on n.oid=c.relnamespace where 
relkind='S' and n.nspname=current_schema() and relname=%(name)s
2016-03-10 18:44:27,115 INFO sqlalchemy.engine.base.Engine {'name': 
u'drop_seq_col'}
2016-03-10 18:44:27,117 INFO sqlalchemy.engine.base.Engine CREATE SEQUENCE 
drop_seq_col
2016-03-10 18:44:27,117 INFO sqlalchemy.engine.base.Engine {}
2016-03-10 18:44:27,127 INFO sqlalchemy.engine.base.Engine COMMIT
2016-03-10 18:44:27,129 INFO sqlalchemy.engine.base.Engine
CREATE TABLE drop_seq_test (
col INTEGER DEFAULT nextval('drop_seq_col') NOT NULL,
source_id SERIAL NOT NULL,
PRIMARY KEY (source_id),
UNIQUE (col)
)


2016-03-10 18:44:27,129 INFO sqlalchemy.engine.base.Engine {}
2016-03-10 18:44:27,147 INFO sqlalchemy.engine.base.Engine COMMIT
2016-03-10 18:44:27,148 INFO sqlalchemy.engine.base.Engine select relname 
from pg_class c join pg_namespace n on n.oid=c.relnamespace where 
pg_catalog.pg_table_is_visible(c.oid) and relname=%(name)s
2016-03-10 18:44:27,148 INFO sqlalchemy.engine.base.Engine {'name': 
u'drop_seq_test'}
2016-03-10 18:44:27,150 INFO sqlalchemy.engine.base.Engine SELECT relname 
FROM pg_class c join pg_namespace n on n.oid=c.relnamespace where 
relkind='S' and n.nspname=current_schema() and relname=%(name)s
2016-03-10 18:44:27,150 INFO sqlalchemy.engine.base.Engine {'name': 
u'drop_seq_col'}
2016-03-10 18:44:27,151 INFO sqlalchemy.engine.base.Engine DROP SEQUENCE 
drop_seq_col
2016-03-10 18:44:27,151 INFO sqlalchemy.engine.base.Engine {}
2016-03-10 18:44:27,152 INFO sqlalchemy.engine.base.Engine ROLLBACK
Traceback (most recent call last):
  File "drop-sequence.py", line 17, in 
metadata.drop_all()
  File 
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/sql/schema.py",
 
line 3722, in drop_all
tables=tables)
  File 
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
 
line 1856, in _run_visitor
conn._run_visitor(visitorcallable, element, **kwargs)
  File 
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
 
line 1481, in _run_visitor
**kwargs).traverse_single(element)
  File 
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/sql/visitors.py",
 
line 121, in traverse_single
return meth(obj, **kw)
  File 
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/sql/ddl.py",
 
line 871, in visit_metadata
table, drop_ok=True, _is_metadata_operation=True)
  File 
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/sql/visitors.py",
 
line 121, in traverse_single
return meth(obj, **kw)
  File 
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/sql/ddl.py",
 
line 916, in visit_table
self.traverse_single(column.default)
  File 
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/sql/visitors.py",
 
line 121, in traverse_single
return meth(obj, **kw)
  File 
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/sql/ddl.py",
 
line 934, in visit_sequence
self.connection.execute(DropSequence(sequence))
  File 
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
 
line 914, in execute
return meth(self, multiparams, params)
  File 
"/Users/jay/.virtualenvs/pinto/lib/python2.7/site-packages/sqlalchemy/sql/ddl.py",
 
line 68, in _execute_on_connection
return connection._execute_ddl(self, multiparams, params)
  File 
"/Us

Re: [sqlalchemy] Determining what, if anything, a Session.merge() does?

2016-03-10 Thread Mike Bayer



On 03/10/2016 08:06 PM, Russ wrote:

Is there any way to tell what the outcome of a Session.merge() operation is?

The case of specific interest is when the instance to be merged *does*
exist prior to the merge() call.  Is there a built in way to see if any
attributes end up updated, or does this need to be checked manually?


to see if attributes are updated you can inspect each one individually 
using the history API 
(http://docs.sqlalchemy.org/en/rel_1_0/orm/internals.html?highlight=history#sqlalchemy.orm.state.AttributeState), 
or to determine this at once the is_modified() method will work 
(http://docs.sqlalchemy.org/en/rel_1_0/orm/session_api.html?highlight=is_modified#sqlalchemy.orm.session.Session.is_modified, 
make sure you read the caveats on this one).


The merge() method will "autoflush" before doing its work, assuming the 
Session has autoflush enabled, so you can be sure these dirty changes 
are a result of the merge operation as long as that flush occurs first.





--
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] Determining what, if anything, a Session.merge() does?

2016-03-10 Thread Russ
Is there any way to tell what the outcome of a Session.merge() operation is?

The case of specific interest is when the instance to be merged *does* 
exist prior to the merge() call.  Is there a built in way to see if any 
attributes end up updated, or does this need to be checked manually?

-- 
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] how to handle SQLite's GUID?

2016-03-10 Thread c.buhtz
Ok, sorry. I used unconcrete words.

I don't want to create something like that.

I want to know which one of the standard SQLAlchemy-offered data types
would be the best fitting to handle (just read and use for UPDATE) a
vendor-column-type like that.

-- 
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] Re: Ways of processing multiple rows with same ID?

2016-03-10 Thread Jonathan Vanasco
What might work for you (if the database is structured as such) would be 
something like this (in pseudocode)

class ProductAttribute(base):
id = column-int, primary key
name = column-unicode

class Product2ProductAttribute(base):
product_id =column-int, part of primary key
product_attribute_id = column-int, part of primary key

product = orm.relationship('Product')
product_attribute = orm.relationship('ProductAttribute')


class Product(base):
id = column-int, primary key

to_attributes = orm.relationship('Product2ProductAttribute')


# this would generate a huge sql matrix like you are now
products = session.query(Product).options(joinedload('to_attributes'), 
joinedload("to_attributes.product_attribute"))

for product in products:
 # the product data 
 print product
 # loop the attributes
 for to_attribute in product.to_attributes:
  print to_attribute.product_attribute.name

 
  


-- 
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: Ways of processing multiple rows with same ID?

2016-03-10 Thread Alex Hall
What I'm doing, and sorry for not explaining further, is making a CSV
file of data. Each row is a row in my results, or would be if I were
just selecting from products. Having to select from attributes as well
is where I'm having problems. Each product can have multiple
attributes, and each attribute value can be assigned to multiple
products. Joining everything (by using filter()) is giving me way too
many results to deal with effectively.

Say we had a product with an ID of 001, a name of "widget", and an
image of "images/001.jpg". This product has a weight and a color, but
those attributes are in the attributevalues table.

Attributes work something like this: attributeassignments has a
product ID and an attribute ID. Attributes has an attribute ID and an
attribute name ("color", "size", and so on). AttributeValues has an
attribute ID and a value ("blue", "55", etc).

For our widget, attributes might have 001, 001, "size"; 001, 002,
"color"; 001, 003, "weight". 001 is the product ID of the widget.
AttributeAssignment might have 001, 001; 001, 002; 001, 003. 001 is
the widget, and the second numbers are the IDs of the different
attributes.
AttributeValues might have 001, "1x2x3"; 002, "blue"; 003, "55".

In the CSV file, I want to put each of those three attributes under a column:
001, Widget, images/001.jpg, blue, 55, 1x2x3

Currently, I'm iterating over the results. The first line inside the
loop, I check the current result's ID and compare it to the previous
one. If they match, I assume I'm on the same result, so I get the
values of the attributes in the row. If the two IDs differ, I assume
I'm done. I write out the values for the last result, clear out the
array I use to store all the values, and grab the new values that
aren't attributes.

My current query does so much joining that my results are too large to
manage, though. The very first iteration works perfectly, but then I
get stuck with the same product ID number. Even when I raise the query
limit to 100,000, I never see any other product ID than that first
one. It feels like an infinite loop, but my loop is simply,
items = 
for result in items:
 ...

I hope this makes more sense. I've re-read the ORM tutorial as
Jonathan suggested, too. The last bit, about many-to-many
relationships, seems like it might be useful. I don't quite follow it
all, but hopefully some of it will make more sense the more I re-read
it.

On 3/10/16, Jonathan Vanasco  wrote:
> 2 comments:
>
> 1.  Go through the SqlAlchemy ORM tutorial.  What you're describing right
> now is dancing around some very basic relationship definition and
> loading/query techniques.
>
> 2. You haven't described what you actually want to accomplish, only some
> general ideas of how you think you could interact with data.  If you want
> to grab a matrix that has every product, there will be one set of ways to
> approach the problem.  If you want to return an iterable list of all
> variations of a certain product, there will be another set of ways.  If you
>
> want to search by specific criteria, there will be yet another set of ways.
>
>  depending on what you do with the data, the query will be different.
>
>
>
>
>
> --
> 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] Re: Ways of processing multiple rows with same ID?

2016-03-10 Thread Jonathan Vanasco
2 comments:

1.  Go through the SqlAlchemy ORM tutorial.  What you're describing right 
now is dancing around some very basic relationship definition and 
loading/query techniques.

2. You haven't described what you actually want to accomplish, only some 
general ideas of how you think you could interact with data.  If you want 
to grab a matrix that has every product, there will be one set of ways to 
approach the problem.  If you want to return an iterable list of all 
variations of a certain product, there will be another set of ways.  If you 
want to search by specific criteria, there will be yet another set of ways. 
 depending on what you do with the data, the query will be different.





-- 
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] how to handle SQLite's GUID?

2016-03-10 Thread Mike Bayer

from sqlalchemy import *
from sqlalchemy.types import UserDefinedType


class GUID(UserDefinedType):
def get_col_spec(self, **kw):
return "GUID"

e = create_engine("sqlite://", echo=True)

m = MetaData()
t = Table(
't', m,
Column('id', GUID),
PrimaryKeyConstraint('id', name="PkReference")
)
m.create_all(e)



output:

CREATE TABLE t (
id GUID NOT NULL,
CONSTRAINT "PkReference" PRIMARY KEY (id)
)



On 03/09/2016 07:11 PM, c.bu...@posteo.jp wrote:

What would be the best and most save way to represent the "GUID PRIMARY
KEY" column type from SQLite3 in a SQLAlchemy schema?

The SQL looks like this

CREATE TABLE Reference (ID GUID CONSTRAINT PK_Reference PRIMARY KEY, ...

The DB ist foreign and not created by me.



--
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] Ways of processing multiple rows with same ID?

2016-03-10 Thread Alex Hall
Hi list,
I'm not sure how to explain this, so let me know if I lose you. I have
the same products database as yesterday, but I've just learned that
product attributes are stored in their own tables. A product can have
many attributes (size, color, weight, etc), and each attribute value
is in a table. That table is tied to the product through an attribute
assignment table, which lets us write "large" once and then assign
that to thousands of products at once, for instance. Essentially, the
item_id is a foreign key into attributeAssignment, which also has an
attr_value_id. That attr_value_id matches the PK in attr_values, which
is the table that actually holds the attribute text.

The problem is that, when I use filter() to join all this stuff
together, I get valueCount*productCount rows. That's not really a
problem, actually, as it's doing what I want. Putting things back
together is going to be a challenge, though. I essentially want, for
example, color and size under the same product ID, but my current
query will return two different rows with the same ID. One row will
have the color, and the next row will have the size. I don't think I
can flatten these out, so my next idea is doing post-query processing
as I iterate through the results.

I'm tempted to just hard-code a sub-loop, to iterate through each n
rows, knowing that n will be the number of rows that share an ID.
Using grouping should make that work. My fear is that I'll get a set
of data which, somehow, has a different size--maybe a missing
attribute--and thus my entire system will be off a row or two. My next
idea is to store the ID of the first row inside the for loop iterating
through all the rows. In that for loop is a while loop: while
IDOfNextRow==currentID: (check IDOfNewRow). That way, I can keep
related rows together and manually pull out the data I need for each
one. Using group-by, I shouldn't ever have a case where a used ID
surfaces again way down the line.

Is there an easier way I haven't thought of? I can't be the first
person to run into this, and SA has a lot of powerful features that
make doing DB work easy, so maybe there's something I just don't know
about. As I said, I'm not so new to SQL that I just started last week,
but neither am I any kind of experienced user at all; maybe SQL itself
can offer something here. Thanks for any information/ideas anyone has,
and again, let me know if I haven't explained this well enough.

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