[sqlalchemy] Tracking new relationships

2017-11-30 Thread Tolstov Sergey
Hi, everyone.

I cannot found information how to find information about new relationships, 
when they related with secondary table.
Inspect can't work with class RelationshipProperty.
 class_mapper.iterate_properties have't information about changed 
attributes

My *task* is:
  Write transactions for all changes, i use them for generate old condition 
of instances
I try to use:
  Write to common table Transcations, data:

classname,
instance_id,
attribute_name,
new_value,
old_value
TransactionsComment - group of transactions (such as *git commit*)

*Example* is:
  users=db.session.query(Group_).first()
  if users is None:
users=Group_(name='users')
db.session.add(users)
db.session.commit()
  print ('now on user')
##New User
  user=db.session.query(User_).first()
  if user is None:
# print ('need new user')
user=User_(login='trololo', groups=[users])
db.session.add(user)
db.session.commit()
  return 'good'

I use *listener "before_commit"*

#update
  for i in db.session.dirty:
tr=[]
print ('\nUpdated   '+i.__class__.__name__+'  '+str(i.__dict__))

for prop in class_mapper(i.__class__).iterate_properties:
  if isinstance(prop, RelationshipProperty):
if prop.parent==i.__mapper__:
  print (str(prop.key))
  print ('try to find '+prop.key+' in '+str(i.__dict__))
  if prop.key in i.__dict__:
print (inspect(i.__dict__[prop.key]))
  # for rel_attr in inspect(prop).attrs:
  #   if rel_attr.history.has_changes:
  # print (str(rel_attr))

  #create
  for i in db.session.new:
print ('\nNew   '+i.__class__.__name__+'  '+str(i.__dict__))
if getattr(i,'Document',False) is not False:
  doc=db.session.query(Document_).first()
  if doc is None:
doc=Document_(name='test', extension='txt')
  print ('added document property to'+str(i.__dict__))
  i.Document=doc

*Result* is
New   Group_  {'name': 'users', 'polymorphic_type': 'group_', 
'_sa_instance_state': }
added document property to{'_sa_instance_state': 
, 'name': 
'users', 'mRID': UUID('1c0a2e32-20b9-4ecf-af62-5cf919e16269'), 
'polymorphic_type': 'group_'}
now on user

Updated   Group_  {'_sa_instance_state': 
}
users
try to find users in {'_sa_instance_state': 
}
childrens
try to find childrens in {'_sa_instance_state': 
}
parents
try to find parents in {'_sa_instance_state': 
}

New   User_  {'login': 'trololo', 'groups': True, '_sa_instance_state': 
, 
'polymorphic_type': 'user_'}
added document property to{'login': 'trololo', 'groups': True, 
'_sa_instance_state': , 'mRID': UUID('c07fe890-8bb4-4b36-abe6-afd85148d005'), 
'polymorphic_type': 'user_'}

Thanks for read my answer, if you have minds how i can find this changes, 
or another path to complete this task i would like to read them

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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] Writing a Table that changes its schema and name if ii's used with PostgreSQL or Oracle

2017-11-30 Thread Massimiliano della Rovere
Greetings,
I'm writing to ask some hints for my problem.

I am using SQLAlchemy Core (no ORM, because everything it is wrapped by 
sqlachemy_aio - everything happens inside a asyncio loop).

The program I'm working on can be deployed with a PostgreSQL or an Oracle 
DB, customer choice, I have no power on this.
My problem is writing Table(s) definitions whose name and schema change 
depending on the DB that will be used.
If the table name is "table" and the schema name is "schema" (I mean the 
schema= parameter of sqlalchemy.schema.Table):
* with PostgreSQL, the table name should be "table" and the schema "schema".
* with Oracle, the table name should be "schema_table" and there should be 
no schema (the default one for the user logging onto Oracle).

With PostgreSQL, the program uses multiple table grouped in different 
schemas, so different Table instances will be grouped in different schema, 
and there will be inter-schema Foreign Keys.
Also the solution should be compatible with Alembic, as it is used for 
versioning.
When the program is deployed, a file contains the information whether the 
DB in use is PostgreSQL or Oracle.

One idea (but I think it won't work with Alembic), is to create a new class 
that inherits from sqlalchemy.schema.Table and overrides the __new__ method:

# python3code
class CustomTable(Table):
def __new__(cls, *args, **kw):
database_type = read_database_type()
if database_type == "oracle":
try:
schema = kw.pop("schema")
except KeyError:
pass
else:
tablename = f"{schema}_{args[0]}"
return super().__new__(cls, tablename, *args[1:], **kw)
return super().__new__(cls, *args, **kw)

It would be nice to create a similar class for Alembic, to customize the 
op.create_table and op.drop_table statement.
Before writing further code, I'd like to ask whether there are built in 
mechanisms in sqlalchemy to address this problem.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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] Replace relationship values with join() call

2017-11-30 Thread Анатолий Иванов
Hi Mike! Thanks for answering. In fact i tried that same code as you posted 
and it did eager load of original (not my subquery) data. However, here 
 i found a 
mention that contains_eager has an alias parameter, so doing 
s.query(A).join(all_b).options(contains_eager(A.b, 
alias=all_b)).all() helped. 

Thanks for helping sort that out!

Anatoly

On Thursday, 30 November 2017 18:22:06 UTC+3, Mike Bayer wrote:
>
> On Thu, Nov 30, 2017 at 8:41 AM, Анатолий Иванов  > wrote: 
> > Hello everyone! 
> > 
> > 
> > TL;DR: 
> > A mapping (class A) has a relationship(to class B). Lazy load is 
> specified. 
> > I want to 
> > 
> > manually select and filter data from B (the result lets call B') 
> > select everything from A 
> > outer join A with B' 
> > 
> > Problem: when doing 
> > 
> > all_b = session.query(B).filter(B.value == 1).subquery() 
> > all_a = session.query(A).join(all_b).all() 
> > 
> > it performs correct SQL request, although, when accessing all_a.b 
> performs 
> > an extra SQL request and selects all B (not B'). How do i make select 
> with 
> > the joined data from my subquery instead of selecting whole data from 
> the 
> > database? 
>
>
> you need to use contains_eager() for that: 
>
> s.query(A).join(all_b).options(contains_eager(A.b)).all() 
>
> docs at 
> http://docs.sqlalchemy.org/en/latest/orm/loading_relationships.html?highlight=contains_eager#contains-eager
>  
>
>
>
>
> > 
> > Long with working code: 
> > 
> > I do some kind of scanner management. Each IP can have several open 
> ports. 
> > 
> > import datetime 
> > from sqlalchemy import create_engine 
> > from sqlalchemy.orm import sessionmaker 
> > from sqlalchemy.pool import NullPool 
> > from sqlalchemy.orm import aliased, joinedload 
> > 
> > from sqlalchemy.orm import relationship 
> > from sqlalchemy.ext.declarative import declarative_base 
> > from sqlalchemy import Column, String, ForeignKey, Table, Integer, 
> DateTime 
> > 
> > 
> > Base = declarative_base() 
> > 
> > association_table = Table( 
> > '_association', Base.metadata, 
> > Column('ip_id', Integer, ForeignKey('_ips.ip_id')), 
> > Column('host_id', Integer, ForeignKey('_hosts.host_id')) 
> > ) 
> > 
> > class Sessions(object): 
> > 
> > def __init__(self): 
> > self.engine = create_engine('postgresql://127.0.0.1/black', 
> > poolclass=NullPool, echo=True) 
> > self.session_builder = sessionmaker(bind=self.engine, 
> > expire_on_commit=False) 
> > 
> > def get_new_session(self): 
> > session = self.session_builder() 
> > 
> > return session 
> > 
> > def destroy_session(self, session): 
> > session.close() 
> > 
> > class IPDatabase(Base): 
> > __tablename__ = '_ips' 
> > 
> > ip_id = Column(Integer, primary_key=True, autoincrement=True) 
> > 
> > # The hostnames that point to this IP 
> > hostnames = relationship( 
> > "HostDatabase", 
> > secondary=association_table, 
> > back_populates="ip_addresses", 
> > lazy='select' 
> > ) 
> > 
> > # Open ports 
> > ports = relationship('PortDatabase', cascade="all, delete-orphan", 
> > lazy='select') 
> > date_added = Column(DateTime, default=datetime.datetime.utcnow) 
> > 
> > def __repr__(self): 
> > return """  IP=(id={}, ports={}) """.format(self.ip_id, 
> self.ports) 
> > 
> > 
> > class PortDatabase(Base): 
> > __tablename__ = '_ports' 
> > 
> > ports_id = Column(Integer, primary_key=True, autoincrement=True) 
> > 
> > data = Column(String) 
> > port_number = Column(Integer) 
> > 
> > date_added = Column(DateTime, default=datetime.datetime.utcnow) 
> > 
> > 
> > # The name of the related project 
> > target = Column( 
> > Integer, ForeignKey('_ips.ip_id', ondelete='CASCADE') 
> > ) 
> > 
> > 
> > def __repr__(self): 
> > return """  Port=(id={}, port={}) """.format(self.ports_id, 
> > self.port_number) 
> > 
> > 
> > def create(): 
> > sessions = Sessions() 
> > 
> > Base.metadata.drop_all(sessions.engine) 
> > Base.metadata.create_all(sessions.engine, checkfirst=True) 
> > 
> > session_spawner = Sessions() 
> > session = session_spawner.get_new_session() 
> > 
> > ip_1 = IPDatabase() 
> > ip_2 = IPDatabase() 
> > ip_3 = IPDatabase() 
> > 
> > port_1 = PortDatabase(port_number=80) 
> > port_2 = PortDatabase(port_number=80) 
> > port_3 = PortDatabase(port_number=443) 
> > 
> > ip_1.ports.append(port_1) 
> > ip_1.ports.append(port_2) 
> > ip_1.ports.append(port_3) 
> > 
> > session.add(ip_1) 
> > session.add(ip_2) 
> > session.add(ip_3) 
> > 
> > session.add(port_1) 
> > session.add(port_2) 
> > session.add(port_3) 
> > 
> > session.commit() 
> > 
> > session_spawner.destroy_session(session) 
> > 
> > def main(): 
> > session_spawner = Sessions() 
> > session = session_spawner

Re: [sqlalchemy] Oracle Boolean Attribute - SQL command not properly ended

2017-11-30 Thread Kevin Foley
Would using not_ be the appropriate way to get non current addresses?

On Thursday, November 30, 2017 at 1:22:56 PM UTC-5, Kevin Foley wrote:
>
> Ah I see,  I was using q = 
> s.query(A.is_current_address).filter(A.is_current_address==True), just 
> using A.is_current_address produces the same results you have.  Thanks!
>
> On Thursday, November 30, 2017 at 12:49:37 PM UTC-5, Mike Bayer wrote:
>>
>> On Thu, Nov 30, 2017 at 10:31 AM, Kevin Foley  wrote: 
>> > I created a Boolean attribute for an Oracle table that checks if an 
>> address 
>> > is the customer's current address. 
>> > 
>> > @is_current_address.expression 
>> > def is_current_address(cls): 
>> > return and_(cls.eff_date <= func.current_date(), cls.term_date 
>> >= 
>> > func.current_date()) 
>> > 
>> > When I try to run a query with this it generates the following where 
>> clause: 
>> > 
>> > WHERE (addresses.eff_date <= CURRENT_DATE AND addresses.term_date >= 
>> > CURRENT_DATE) = 1 
>>
>>
>> can you show me the "try to run a query" part, because that expression 
>> alone would not be doing the "= 1" thing you are describing.   it 
>> would do that if it were being interpreted in some boolean context 
>> like "expr == True" or something like that. 
>>
>> Here's an MCVE: 
>>
>> from sqlalchemy import * 
>> from sqlalchemy.orm import * 
>> from sqlalchemy.ext.declarative import declarative_base 
>> from sqlalchemy.ext.hybrid import hybrid_property 
>> import datetime 
>> from sqlalchemy.dialects import oracle 
>>
>> Base = declarative_base() 
>>
>>
>> class A(Base): 
>> __tablename__ = 'a' 
>> id = Column(Integer, primary_key=True) 
>> eff_date = Column(DateTime) 
>> term_date = Column(DateTime) 
>>
>> @hybrid_property 
>> def is_current_address(self): 
>> return self.eff_date <= datetime.datetime.now() and \ 
>> self.term_date >= datetime.datetime.now() 
>>
>> @is_current_address.expression 
>> def is_current_address(cls): 
>> return and_( 
>> cls.eff_date <= func.current_date(), 
>> cls.term_date >= func.current_date()) 
>>
>> s = Session() 
>>
>> q = s.query(A.is_current_address).filter(A.is_current_address) 
>>
>> print q.statement.compile(dialect=oracle.dialect()) 
>>
>>
>> output: 
>>
>> SELECT a.eff_date <= CURRENT_DATE AND a.term_date >= CURRENT_DATE AS 
>> is_current_address 
>> FROM a 
>> WHERE a.eff_date <= CURRENT_DATE AND a.term_date >= CURRENT_DATE 
>>
>> tried it back to 1.0.x doesn't render an =1 
>>
>>
>>
>>
>>
>>
>> > 
>> > and generates the Oracle  error: 
>> > 
>> >> ORA-00933: SQL command not properly ended 
>> > 
>> > 
>> > I believe this type of expression isn't supported in Oracle, however 
>> > manually removing the "= 1" from the clause makes the query work.  Is 
>> there 
>> > a different approach I need to take to make sure this is handled 
>> properly? 
>> > 
>> > -- 
>> > SQLAlchemy - 
>> > The Python SQL Toolkit and Object Relational Mapper 
>> > 
>> > http://www.sqlalchemy.org/ 
>> > 
>> > To post example code, please provide an MCVE: Minimal, Complete, and 
>> > Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
>> > description. 
>> > --- 
>> > 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+...@googlegroups.com. 
>> > To post to this group, send email to sqlal...@googlegroups.com. 
>> > Visit this group at https://groups.google.com/group/sqlalchemy. 
>> > For more options, visit https://groups.google.com/d/optout. 
>>
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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] Oracle Boolean Attribute - SQL command not properly ended

2017-11-30 Thread Kevin Foley
Ah I see,  I was using q = 
s.query(A.is_current_address).filter(A.is_current_address==True), just 
using A.is_current_address produces the same results you have.  Thanks!

On Thursday, November 30, 2017 at 12:49:37 PM UTC-5, Mike Bayer wrote:
>
> On Thu, Nov 30, 2017 at 10:31 AM, Kevin Foley  > wrote: 
> > I created a Boolean attribute for an Oracle table that checks if an 
> address 
> > is the customer's current address. 
> > 
> > @is_current_address.expression 
> > def is_current_address(cls): 
> > return and_(cls.eff_date <= func.current_date(), cls.term_date 
> >= 
> > func.current_date()) 
> > 
> > When I try to run a query with this it generates the following where 
> clause: 
> > 
> > WHERE (addresses.eff_date <= CURRENT_DATE AND addresses.term_date >= 
> > CURRENT_DATE) = 1 
>
>
> can you show me the "try to run a query" part, because that expression 
> alone would not be doing the "= 1" thing you are describing.   it 
> would do that if it were being interpreted in some boolean context 
> like "expr == True" or something like that. 
>
> Here's an MCVE: 
>
> from sqlalchemy import * 
> from sqlalchemy.orm import * 
> from sqlalchemy.ext.declarative import declarative_base 
> from sqlalchemy.ext.hybrid import hybrid_property 
> import datetime 
> from sqlalchemy.dialects import oracle 
>
> Base = declarative_base() 
>
>
> class A(Base): 
> __tablename__ = 'a' 
> id = Column(Integer, primary_key=True) 
> eff_date = Column(DateTime) 
> term_date = Column(DateTime) 
>
> @hybrid_property 
> def is_current_address(self): 
> return self.eff_date <= datetime.datetime.now() and \ 
> self.term_date >= datetime.datetime.now() 
>
> @is_current_address.expression 
> def is_current_address(cls): 
> return and_( 
> cls.eff_date <= func.current_date(), 
> cls.term_date >= func.current_date()) 
>
> s = Session() 
>
> q = s.query(A.is_current_address).filter(A.is_current_address) 
>
> print q.statement.compile(dialect=oracle.dialect()) 
>
>
> output: 
>
> SELECT a.eff_date <= CURRENT_DATE AND a.term_date >= CURRENT_DATE AS 
> is_current_address 
> FROM a 
> WHERE a.eff_date <= CURRENT_DATE AND a.term_date >= CURRENT_DATE 
>
> tried it back to 1.0.x doesn't render an =1 
>
>
>
>
>
>
> > 
> > and generates the Oracle  error: 
> > 
> >> ORA-00933: SQL command not properly ended 
> > 
> > 
> > I believe this type of expression isn't supported in Oracle, however 
> > manually removing the "= 1" from the clause makes the query work.  Is 
> there 
> > a different approach I need to take to make sure this is handled 
> properly? 
> > 
> > -- 
> > SQLAlchemy - 
> > The Python SQL Toolkit and Object Relational Mapper 
> > 
> > http://www.sqlalchemy.org/ 
> > 
> > To post example code, please provide an MCVE: Minimal, Complete, and 
> > Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> > description. 
> > --- 
> > 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+...@googlegroups.com . 
> > To post to this group, send email to sqlal...@googlegroups.com 
> . 
> > Visit this group at https://groups.google.com/group/sqlalchemy. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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] Oracle Boolean Attribute - SQL command not properly ended

2017-11-30 Thread Mike Bayer
On Thu, Nov 30, 2017 at 10:31 AM, Kevin Foley  wrote:
> I created a Boolean attribute for an Oracle table that checks if an address
> is the customer's current address.
>
> @is_current_address.expression
> def is_current_address(cls):
> return and_(cls.eff_date <= func.current_date(), cls.term_date >=
> func.current_date())
>
> When I try to run a query with this it generates the following where clause:
>
> WHERE (addresses.eff_date <= CURRENT_DATE AND addresses.term_date >=
> CURRENT_DATE) = 1


can you show me the "try to run a query" part, because that expression
alone would not be doing the "= 1" thing you are describing.   it
would do that if it were being interpreted in some boolean context
like "expr == True" or something like that.

Here's an MCVE:

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.hybrid import hybrid_property
import datetime
from sqlalchemy.dialects import oracle

Base = declarative_base()


class A(Base):
__tablename__ = 'a'
id = Column(Integer, primary_key=True)
eff_date = Column(DateTime)
term_date = Column(DateTime)

@hybrid_property
def is_current_address(self):
return self.eff_date <= datetime.datetime.now() and \
self.term_date >= datetime.datetime.now()

@is_current_address.expression
def is_current_address(cls):
return and_(
cls.eff_date <= func.current_date(),
cls.term_date >= func.current_date())

s = Session()

q = s.query(A.is_current_address).filter(A.is_current_address)

print q.statement.compile(dialect=oracle.dialect())


output:

SELECT a.eff_date <= CURRENT_DATE AND a.term_date >= CURRENT_DATE AS
is_current_address
FROM a
WHERE a.eff_date <= CURRENT_DATE AND a.term_date >= CURRENT_DATE

tried it back to 1.0.x doesn't render an =1






>
> and generates the Oracle  error:
>
>> ORA-00933: SQL command not properly ended
>
>
> I believe this type of expression isn't supported in Oracle, however
> manually removing the "= 1" from the clause makes the query work.  Is there
> a different approach I need to take to make sure this is handled properly?
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> 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 - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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: Dictionaries with mapped objects as keys and integers as values

2017-11-30 Thread Sven
It works admirably well. Again, thank you very much for the support you 
provide.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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] Oracle Boolean Attribute - SQL command not properly ended

2017-11-30 Thread Kevin Foley
I created a Boolean attribute for an Oracle table that checks if an address 
is the customer's current address.

@is_current_address.expression
def is_current_address(cls):
return and_(cls.eff_date <= func.current_date(), cls.term_date >= 
func.current_date())

When I try to run a query with this it generates the following where clause:

WHERE (addresses.eff_date <= CURRENT_DATE AND addresses.term_date >= 
CURRENT_DATE) = 1

and generates the Oracle  error: 

ORA-00933: SQL command not properly ended
>
>
I believe this type of expression isn't supported in Oracle, however 
manually removing the "= 1" from the clause makes the query work.  Is there 
a different approach I need to take to make sure this is handled properly?

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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] Replace relationship values with join() call

2017-11-30 Thread Mike Bayer
On Thu, Nov 30, 2017 at 8:41 AM, Анатолий Иванов  wrote:
> Hello everyone!
>
>
> TL;DR:
> A mapping (class A) has a relationship(to class B). Lazy load is specified.
> I want to
>
> manually select and filter data from B (the result lets call B')
> select everything from A
> outer join A with B'
>
> Problem: when doing
>
> all_b = session.query(B).filter(B.value == 1).subquery()
> all_a = session.query(A).join(all_b).all()
>
> it performs correct SQL request, although, when accessing all_a.b performs
> an extra SQL request and selects all B (not B'). How do i make select with
> the joined data from my subquery instead of selecting whole data from the
> database?


you need to use contains_eager() for that:

s.query(A).join(all_b).options(contains_eager(A.b)).all()

docs at 
http://docs.sqlalchemy.org/en/latest/orm/loading_relationships.html?highlight=contains_eager#contains-eager




>
> Long with working code:
>
> I do some kind of scanner management. Each IP can have several open ports.
>
> import datetime
> from sqlalchemy import create_engine
> from sqlalchemy.orm import sessionmaker
> from sqlalchemy.pool import NullPool
> from sqlalchemy.orm import aliased, joinedload
>
> from sqlalchemy.orm import relationship
> from sqlalchemy.ext.declarative import declarative_base
> from sqlalchemy import Column, String, ForeignKey, Table, Integer, DateTime
>
>
> Base = declarative_base()
>
> association_table = Table(
> '_association', Base.metadata,
> Column('ip_id', Integer, ForeignKey('_ips.ip_id')),
> Column('host_id', Integer, ForeignKey('_hosts.host_id'))
> )
>
> class Sessions(object):
>
> def __init__(self):
> self.engine = create_engine('postgresql://127.0.0.1/black',
> poolclass=NullPool, echo=True)
> self.session_builder = sessionmaker(bind=self.engine,
> expire_on_commit=False)
>
> def get_new_session(self):
> session = self.session_builder()
>
> return session
>
> def destroy_session(self, session):
> session.close()
>
> class IPDatabase(Base):
> __tablename__ = '_ips'
>
> ip_id = Column(Integer, primary_key=True, autoincrement=True)
>
> # The hostnames that point to this IP
> hostnames = relationship(
> "HostDatabase",
> secondary=association_table,
> back_populates="ip_addresses",
> lazy='select'
> )
>
> # Open ports
> ports = relationship('PortDatabase', cascade="all, delete-orphan",
> lazy='select')
> date_added = Column(DateTime, default=datetime.datetime.utcnow)
>
> def __repr__(self):
> return """  IP=(id={}, ports={}) """.format(self.ip_id, self.ports)
>
>
> class PortDatabase(Base):
> __tablename__ = '_ports'
>
> ports_id = Column(Integer, primary_key=True, autoincrement=True)
>
> data = Column(String)
> port_number = Column(Integer)
>
> date_added = Column(DateTime, default=datetime.datetime.utcnow)
>
>
> # The name of the related project
> target = Column(
> Integer, ForeignKey('_ips.ip_id', ondelete='CASCADE')
> )
>
>
> def __repr__(self):
> return """  Port=(id={}, port={}) """.format(self.ports_id,
> self.port_number)
>
>
> def create():
> sessions = Sessions()
>
> Base.metadata.drop_all(sessions.engine)
> Base.metadata.create_all(sessions.engine, checkfirst=True)
>
> session_spawner = Sessions()
> session = session_spawner.get_new_session()
>
> ip_1 = IPDatabase()
> ip_2 = IPDatabase()
> ip_3 = IPDatabase()
>
> port_1 = PortDatabase(port_number=80)
> port_2 = PortDatabase(port_number=80)
> port_3 = PortDatabase(port_number=443)
>
> ip_1.ports.append(port_1)
> ip_1.ports.append(port_2)
> ip_1.ports.append(port_3)
>
> session.add(ip_1)
> session.add(ip_2)
> session.add(ip_3)
>
> session.add(port_1)
> session.add(port_2)
> session.add(port_3)
>
> session.commit()
>
> session_spawner.destroy_session(session)
>
> def main():
> session_spawner = Sessions()
> session = session_spawner.get_new_session()
>
> subq = session.query(PortDatabase).filter(PortDatabase.port_number ==
> 80).subquery()
>
> ips = session.query(IPDatabase).join(subq).all()
>
> session_spawner.destroy_session(session)
>
> print(ips)  # This will fail, as 'ports' were not loaded due to
> lazyload='select'
>
> if __name__ == '__main__':
> main()
>
>
> Any help would be really great, as i have read tons of manuals and other
> resources, but still cannot find the solution.
>
> Thanks,
> Anatoly
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> 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

Re: [sqlalchemy] Influencing what CREATE statement generated in sqlalchemy

2017-11-30 Thread Mike Bayer
On Thu, Nov 30, 2017 at 5:32 AM, su-sa  wrote:
> Hi everyone,
>
> does someone maybe know if one can from the dialect somehow influence what
> CREATE TABLE statement would be generated in certain cases?
>
> So for example: In the tests for temporary table I saw that for Oracle, the
> create table statement has been adjusted, but that only ís a hack to make
> the tests pass and what if someone really wants to create a temporary table
> using oracle(for ex. CREATE GLOBAL TEMPORARY TABLE) and sqlalchemy?  As far
> as I understood, one cannot in the sqlalchemy framework influence the CREATE
> TABLE statement, or am I wrong?
>
> Another question, is there also a way in sqlalchemy to specify if one wants
> to make a column table or row table? Couldn't really find something similar.

If you just want simple CREATE  TABLE, use the prefixes argument:

from sqlalchemy import *
from sqlalchemy.schema import CreateTable

m = MetaData()
t = Table(
't', m, Column('x', Integer),
prefixes=["GLOBAL", "TEMPORARY"]
)

print CreateTable(t)

for more elaborate things you can affect CREATE TABLE by providing a
compiler function for the CreateTable class:

from sqlalchemy import *
from sqlalchemy.schema import CreateTable
from sqlalchemy.ext.compiler import compiles

@compiles(CreateTable)
def _add_global_thing(element, compiler, **kw):
text = compiler.visit_create_table(element, **kw)
if element.element.info.get('global_temporary', False):
text = text.replace("CREATE TABLE", "CREATE GLOBAL TEMPORARY TABLE")
return text

m = MetaData()
t = Table(
't', m, Column('x', Integer),
info={"global_temporary": True}
)

print CreateTable(t)



>
> Thanks in advance,
> S
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> 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 - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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: Replace relationship values with join() call

2017-11-30 Thread Анатолий Иванов
association_table is not needed here, forgot to remove it, when minimizing 
the code, sorry.

On Thursday, 30 November 2017 16:41:05 UTC+3, Анатолий Иванов wrote:
>
> Hello everyone!
>
>
> *TL;DR:*
> A mapping (class A) has a relationship(to class B). Lazy load is 
> specified. I want to 
>
>1. manually select and filter data from B (the result lets call B')
>2. select everything from A
>3. outer join A with B'
>
> Problem: when doing 
>
> all_b = session.query(B).filter(B.value == 1).subquery()
> all_a = session.query(A).join(all_b).all()
>
> it performs correct SQL request, although, when accessing all_a.b performs 
> an extra SQL request and selects all B (not B'). How do i make select with 
> the joined data from my subquery instead of selecting whole data from the 
> database?
>
> *Long with working code:*
>
> I do some kind of scanner management. Each IP can have several open ports.
>
> import datetime
> from sqlalchemy import create_engine
> from sqlalchemy.orm import sessionmaker
> from sqlalchemy.pool import NullPool
> from sqlalchemy.orm import aliased, joinedload
>
> from sqlalchemy.orm import relationship
> from sqlalchemy.ext.declarative import declarative_base
> from sqlalchemy import Column, String, ForeignKey, Table, Integer, DateTime
>
>
> Base = declarative_base()
>
> association_table = Table(
> '_association', Base.metadata,
> Column('ip_id', Integer, ForeignKey('_ips.ip_id')),
> Column('host_id', Integer, ForeignKey('_hosts.host_id'))
> )
>
> class Sessions(object):
>
> def __init__(self):
> self.engine = create_engine('postgresql://127.0.0.1/black', 
> poolclass=NullPool, echo=True)
> self.session_builder = sessionmaker(bind=self.engine, 
> expire_on_commit=False)
>
> def get_new_session(self):
> session = self.session_builder()
>
> return session
>
> def destroy_session(self, session):
> session.close()
>
> class IPDatabase(Base):
> __tablename__ = '_ips'
>
> ip_id = Column(Integer, primary_key=True, autoincrement=True)
>
> # The hostnames that point to this IP
> hostnames = relationship(
> "HostDatabase",
> secondary=association_table,
> back_populates="ip_addresses",
> lazy='select'
> )
>
> # Open ports
> ports = relationship('PortDatabase', cascade="all, delete-orphan", 
> lazy='select')
> date_added = Column(DateTime, default=datetime.datetime.utcnow)
>
> def __repr__(self):
> return """  IP=(id={}, ports={}) """.format(self.ip_id, self.ports)
>
>
> class PortDatabase(Base):
> __tablename__ = '_ports'
>
> ports_id = Column(Integer, primary_key=True, autoincrement=True)
>
> data = Column(String)
> port_number = Column(Integer)
>
> date_added = Column(DateTime, default=datetime.datetime.utcnow)
>
>
> # The name of the related project
> target = Column(
> Integer, ForeignKey('_ips.ip_id', ondelete='CASCADE')
> )
>
>
> def __repr__(self):
> return """  Port=(id={}, port={}) """.format(self.ports_id, 
> self.port_number)
>
>
> def create():
> sessions = Sessions()
>
> Base.metadata.drop_all(sessions.engine)
> Base.metadata.create_all(sessions.engine, checkfirst=True)
>
> session_spawner = Sessions()
> session = session_spawner.get_new_session()
>
> ip_1 = IPDatabase()
> ip_2 = IPDatabase()
> ip_3 = IPDatabase()
>
> port_1 = PortDatabase(port_number=80)
> port_2 = PortDatabase(port_number=80)
> port_3 = PortDatabase(port_number=443)
>
> ip_1.ports.append(port_1)
> ip_1.ports.append(port_2)
> ip_1.ports.append(port_3)
>
> session.add(ip_1)
> session.add(ip_2)
> session.add(ip_3)
>
> session.add(port_1)
> session.add(port_2)
> session.add(port_3)
>
> session.commit()
>
> session_spawner.destroy_session(session)
>
> def main():
> session_spawner = Sessions()
> session = session_spawner.get_new_session()
>
> subq = session.query(PortDatabase).filter(PortDatabase.port_number == 
> 80).subquery()
>
> ips = session.query(IPDatabase).join(subq).all()
>
> session_spawner.destroy_session(session)
>
> print(ips)  # This will fail, as 'ports' were not loaded due to 
> lazyload='select'
>
> if __name__ == '__main__':
> main()
>
>
> Any help would be really great, as i have read tons of manuals and other 
> resources, but still cannot find the solution.
>
> Thanks,
> Anatoly
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 s

[sqlalchemy] Replace relationship values with join() call

2017-11-30 Thread Анатолий Иванов
Hello everyone!


*TL;DR:*
A mapping (class A) has a relationship(to class B). Lazy load is specified. 
I want to 

   1. manually select and filter data from B (the result lets call B')
   2. select everything from A
   3. outer join A with B'

Problem: when doing 

all_b = session.query(B).filter(B.value == 1).subquery()
all_a = session.query(A).join(all_b).all()

it performs correct SQL request, although, when accessing all_a.b performs 
an extra SQL request and selects all B (not B'). How do i make select with 
the joined data from my subquery instead of selecting whole data from the 
database?

*Long with working code:*

I do some kind of scanner management. Each IP can have several open ports.

import datetime
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.pool import NullPool
from sqlalchemy.orm import aliased, joinedload

from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, String, ForeignKey, Table, Integer, DateTime


Base = declarative_base()

association_table = Table(
'_association', Base.metadata,
Column('ip_id', Integer, ForeignKey('_ips.ip_id')),
Column('host_id', Integer, ForeignKey('_hosts.host_id'))
)

class Sessions(object):

def __init__(self):
self.engine = create_engine('postgresql://127.0.0.1/black', 
poolclass=NullPool, echo=True)
self.session_builder = sessionmaker(bind=self.engine, 
expire_on_commit=False)

def get_new_session(self):
session = self.session_builder()

return session

def destroy_session(self, session):
session.close()

class IPDatabase(Base):
__tablename__ = '_ips'

ip_id = Column(Integer, primary_key=True, autoincrement=True)

# The hostnames that point to this IP
hostnames = relationship(
"HostDatabase",
secondary=association_table,
back_populates="ip_addresses",
lazy='select'
)

# Open ports
ports = relationship('PortDatabase', cascade="all, delete-orphan", 
lazy='select')
date_added = Column(DateTime, default=datetime.datetime.utcnow)

def __repr__(self):
return """  IP=(id={}, ports={}) """.format(self.ip_id, self.ports)


class PortDatabase(Base):
__tablename__ = '_ports'

ports_id = Column(Integer, primary_key=True, autoincrement=True)

data = Column(String)
port_number = Column(Integer)

date_added = Column(DateTime, default=datetime.datetime.utcnow)


# The name of the related project
target = Column(
Integer, ForeignKey('_ips.ip_id', ondelete='CASCADE')
)


def __repr__(self):
return """  Port=(id={}, port={}) """.format(self.ports_id, 
self.port_number)


def create():
sessions = Sessions()

Base.metadata.drop_all(sessions.engine)
Base.metadata.create_all(sessions.engine, checkfirst=True)

session_spawner = Sessions()
session = session_spawner.get_new_session()

ip_1 = IPDatabase()
ip_2 = IPDatabase()
ip_3 = IPDatabase()

port_1 = PortDatabase(port_number=80)
port_2 = PortDatabase(port_number=80)
port_3 = PortDatabase(port_number=443)

ip_1.ports.append(port_1)
ip_1.ports.append(port_2)
ip_1.ports.append(port_3)

session.add(ip_1)
session.add(ip_2)
session.add(ip_3)

session.add(port_1)
session.add(port_2)
session.add(port_3)

session.commit()

session_spawner.destroy_session(session)

def main():
session_spawner = Sessions()
session = session_spawner.get_new_session()

subq = session.query(PortDatabase).filter(PortDatabase.port_number == 
80).subquery()

ips = session.query(IPDatabase).join(subq).all()

session_spawner.destroy_session(session)

print(ips)  # This will fail, as 'ports' were not loaded due to 
lazyload='select'

if __name__ == '__main__':
main()


Any help would be really great, as i have read tons of manuals and other 
resources, but still cannot find the solution.

Thanks,
Anatoly

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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] Possible Exceptions

2017-11-30 Thread Lars Liedtke (SCC)


Am 29.11.2017 um 17:16 schrieb Mike Bayer:
> On Wed, Nov 29, 2017 at 11:12 AM, Mike Bayer  wrote:
>> On Wed, Nov 29, 2017 at 3:37 AM,   wrote:
>>> Hello everybody,
>>>
>>> I am writing some piece of code, which should not exit unforseen in the best
>>> case, at least it should write to a log file what went wrong (e.g. Database
>>> not reachable, etc). So I tried figuring out, which Exceptions would be
>>> possibly thrown by SQLAlchemy:
> let me also add that if "unforseen exit" is the issue, you're mostly
> going to look for the SQL-related errors thrown by the driver which on
> the SQLAlchemy side are the DBAPIError classes, however even in that
> case, some of those errors mean "couldn't connect to the database",
> which could be mis-configuration OR the database is down, others can
> mean "SQL is wrong".   So even then it's hard to know ahead of time
> what conditions can be caught and handled vs. which ones mean the
> program needs to be re-configured and restarted.
Of course, In my case it will be a call from the crontab starting my
process regularly, I just wanted my process not to exit without writing
it to the logfile what the problem was with a "nicely" formatted
message, so the logfiles can be checked for certain messages in ELK. So
I think I can limit them down to if there is an error connecting to the
database because the queries are pretty much fixed and only differ in
which element(s) I query and of course I have to make sure that the
configuration is correct.
>
>
>
>
>> the exception classes are documented at:
>>
>> http://docs.sqlalchemy.org/en/latest/core/exceptions.html
>> http://docs.sqlalchemy.org/en/latest/orm/exceptions.html
>>
>> i will note that while the ORM exceptions are linked from the front
>> page of the docs, the Core ones are not, you need to go into the full
>> table of contents to see it
>> (http://docs.sqlalchemy.org/en/latest/contents.html).
>>
>> as to the exact codepath that can raise these, it depends on the
>> exception.   The docstrings for the exceptions themselves can of
>> course have some additional detail as to what kinds of operations
>> might raise them.Though generic ones like "InvalidRequestError" or
>> "ArgumentError" are thrown in dozens of places wherever the library is
>> asked to do something that doesn't make sense or function arguments
>> that don't make sense are detected.
Thank you very much, I must have not seen the Link.
>>
>>> The first thing I did was googling for how to find out which Exceptions
>>> could be thrown in Python. The answers I found on Stack Overflow etc. were
>>> like "You simply don't", "This is Python, dumbass, you can't predict which
>>> are thrown so don't even try" or "Just write tests until you found them all"
>>> and "Just catch the general Exception class."
>>> So I tried looking at the SQLAlchemy Documentation to see if there is
>>> something written about when something goes wrong, but still no luck.
>>> Before I started digging into the code I thought I'd ask here first
>>>
>>> So is there any hint to know which Exceptions could be thrown by SQLAlchemy?
>>> The error cases I could think of were mostly wrrors while connecting to the
>>> database or having errors in queries. I would totally be willing to help
>>> with documenting at a certain point but even for this I need to know if I
>>> just did't find any documentation for this and if you consider this as
>>> neccessary. I feel that it is neccessary for me not just to kill the process
>>> with maybe a stack trace on stdout.
>>>
>>>
>>> Cheers
>>>
>>> Lars Liedtke
>>>
>>> --
>>> SQLAlchemy -
>>> The Python SQL Toolkit and Object Relational Mapper
>>>
>>> http://www.sqlalchemy.org/
>>>
>>> To post example code, please provide an MCVE: Minimal, Complete, and
>>> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
>>> description.
>>> ---
>>> 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.

-- 
Karlsruher Institut für Technologie (KIT)
Steinbuch Centre für Computing (SCC)

B.Sc. Lars Liedtke
Administrator bwSync&Share

Hermann-von-Helmholtz-Platz 1
Gebaäude 441/Raum 233
D-76344 Eggenstein-Leopoldshafen

Telefon: +49 721 608-28875
Fax: +49 721 608-24972
E-Mail: Lars.Liedtke∂kit.edu
Web: www.scc.kit.edu  

KIT – Die Forschungsuniversität in der Helmholtz-Gemeinschaft

Das KIT ist seit 2010 als familiengerechte Hochschule zertifiziert.


-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full

[sqlalchemy] Influencing what CREATE statement generated in sqlalchemy

2017-11-30 Thread su-sa
Hi everyone,

does someone maybe know if one can from the dialect somehow influence what 
CREATE TABLE statement would be generated in certain cases? 

So for example: In the tests for temporary table I saw that for Oracle, the 
create table statement has been adjusted, but that only ís a hack to make 
the tests pass and what if someone really wants to create a temporary table 
using oracle(for ex. CREATE GLOBAL TEMPORARY TABLE) and sqlalchemy?  As far 
as I understood, one cannot in the sqlalchemy framework influence the 
CREATE TABLE statement, or am I wrong?

Another question, is there also a way in sqlalchemy to specify if one wants 
to make a column table or row table? Couldn't really find something similar.

Thanks in advance,
S

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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.