Re: [sqlalchemy] Re: Select * but apply distinct to one column

2016-03-09 Thread Jonathan Vanasco
If that ID is the primary key, then don't bother with a DISTINCT(). Just select everything from the table. Otherwise you're going to make the backend select everything , then waste time doing the distinct. A quick way to confirm would be to just run these 2 commands: SELECT

[sqlalchemy] how to handle SQLite's GUID?

2016-03-09 Thread c.buhtz
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

Re: [sqlalchemy] Re: properties of query results if names overlap?

2016-03-09 Thread Mike Bayer
the name overlap situation is much improved in 1.1 to where it almost doesn't matter anymore: http://docs.sqlalchemy.org/en/latest/changelog/migration_11.html#positional-matching-is-trusted-over-name-based-matching-for-core-orm-sql-constructs On 03/09/2016 05:40 PM, Alex Hall wrote: I think

[sqlalchemy] Re: properties of query results if names overlap?

2016-03-09 Thread Alex Hall
I think I answered my own question: the result variable gets properties named for the column names, as usual, but those properties are each under their respective table names. Those table names come from the actual table name (I'm using auto-map) or, presumably, the __tablename__ variable for

Re: [sqlalchemy] Re: Select * but apply distinct to one column

2016-03-09 Thread Alex Hall
That makes sense. Part of my problem is that, as I've mentioned in the past, I was recently hired. I didn't set anything up, and I still don't know for sure what I can trust to be unique, or 6 versus 8 characters, or a lot of other small details. That said, SSMS shows the item ID as a primary key,

[sqlalchemy] properties of query results if names overlap?

2016-03-09 Thread Alex Hall
Hi all, Just a quick question: what does SA do if names overlap? For example, in assignmentTable, there's a column called itm_id. In attachmentTable, there's also a column called itm_id, and there's one in itemTable as well. If I combine these in a kind of join, as in: results =

Re: [sqlalchemy] Re: Select * but apply distinct to one column

2016-03-09 Thread Jonathan Vanasco
On Wednesday, March 9, 2016 at 3:02:05 PM UTC-5, Alex Hall wrote: > > Fair enough, thanks. I didn't realize it was such a complex task; I > figured it was just a matter of passing an argument to distinct() or > something equally easy. > Yeah PostgreSQL is the only db that supports "DISTINCT

Re: [sqlalchemy] session flush inserts performing VERY slow for MS Sql Server

2016-03-09 Thread Jonathan Vanasco
On Wednesday, March 9, 2016 at 3:17:26 PM UTC-5, jbrow...@clearcosthealth.com wrote: > > Like I said I am not terribly network savvy but what I meant was that the > particular vpn client that I am using says that my "connection speed" is > ~540Mpbs. > That's most-likely a speed to your

Re: [sqlalchemy] session flush inserts performing VERY slow for MS Sql Server

2016-03-09 Thread jbrownstein
Like I said I am not terribly network savvy but what I meant was that the particular vpn client that I am using says that my "connection speed" is ~540Mpbs. I know comparing sql alchemy to raw sql is kind of a no-no but I was just illustrating that the there isn't obvious evidence of a slow

Re: [sqlalchemy] mssql: UnicodeDecodeError: 'utf8' codec can't decode byte

2016-03-09 Thread Mike Bayer
ah no that one looks like this e = create_engine("mssql+pyodbc://user:pass@dsn", convert_unicode=True, encoding="utf8") On 03/09/2016 03:03 PM, Tim Pierson wrote: Thanks. So that would be a matter of adding convert_unicode=True to the connection string? . . .

Re: [sqlalchemy] Select * but apply distinct to one column

2016-03-09 Thread Mike Bayer
On 03/09/2016 01:38 PM, Alex Hall wrote: Hi all, I want to select * from a table, getting all columns. However, the only rows I want are where the item number is distinct. I've got: items = session.query(itemTable)\ .distinct()\ .limit(10) But that doesn't apply "distinct" to just item_number.

Re: [sqlalchemy] Re: Select * but apply distinct to one column

2016-03-09 Thread Alex Hall
Fair enough, thanks. I didn't realize it was such a complex task; I figured it was just a matter of passing an argument to distinct() or something equally easy. Speed isn't a huge concern, so I suppose I could get around this by storing the item numbers I find and then checking that the row I'm

Re: [sqlalchemy] session flush inserts performing VERY slow for MS Sql Server

2016-03-09 Thread Jonathan Vanasco
Those aren't the same inserts as SqlAlchemy The SQL you noted above (DECLARE / BEGIN/ END) is one packet of text that is sent over the wire to the database server and executed. (a few hundred bytes) A more appropriate comparison would be sending 1000 separate "INSERT INTO " statements

Re: [sqlalchemy] session flush inserts performing VERY slow for MS Sql Server

2016-03-09 Thread Mike Bayer
On 03/09/2016 11:56 AM, jbrownst...@clearcosthealth.com wrote: This is all extremely helpful. After some hair pulling I was able to get the local sql server express running and I ran the same test on a local instance. 10100.1260.0000.1260.000 {method 'execute' of

[sqlalchemy] Re: Select * but apply distinct to one column

2016-03-09 Thread Jonathan Vanasco
It would probably be best for you to figure out the correct raw sql you want, then convert it to SqlAlchemy. Postgres is the only DB I know of that offers "DISTINCT ON (columns)" -- and even that works a bit awkward. The query that you want to do isn't actually simple -- there are concerns

Re: [sqlalchemy] mssql: UnicodeDecodeError: 'utf8' codec can't decode byte

2016-03-09 Thread Mike Bayer
OK what you can try here that might resolve all the issues is to only pass encoded utf8 to the app (and also receive it on the way back); you can do that by setting convert_unicode=True at the create_engine() level where will take effect for all String columns. Technically if you're storing

[sqlalchemy] Select * but apply distinct to one column

2016-03-09 Thread Alex Hall
Hi all, I want to select * from a table, getting all columns. However, the only rows I want are where the item number is distinct. I've got: items = session.query(itemTable)\ .distinct()\ .limit(10) But that doesn't apply "distinct" to just item_number. I'm not the best with SQL in general or I'd

Re: [sqlalchemy] session flush inserts performing VERY slow for MS Sql Server

2016-03-09 Thread jbrownstein
This is all extremely helpful. After some hair pulling I was able to get the local sql server express running and I ran the same test on a local instance. 10100.1260.0000.1260.000 {method 'execute' of 'pyodbc.Cursor' objects} 10100.0600.0000.0600.000

Re: [sqlalchemy] mssql: UnicodeDecodeError: 'utf8' codec can't decode byte

2016-03-09 Thread Tim Pierson
Python 2.7, on windows using pyodbc and whatever the default driver is. Not sure if the problem exists on FreeTDS. Here's an example of the ProgrammingError that is raised when I don't cast the filter() query parameter text: File "C:\Python27\lib\site-packages\sqlalchemy\orm\query.py", line

Alembic 0.8.5 Released

2016-03-09 Thread Mike Bayer
Alembic 0.8.5 is now available. Version 0.8.5 includes a short set of bugfixes. See http://alembic.readthedocs.org/en/latest/changelog.html#change-0.8.5. Download Alembic 0.8.5 at: https://pypi.python.org/pypi/alembic -- You received this message because you are subscribed to the Google

[sqlalchemy] Alembic 0.8.5 Released

2016-03-09 Thread Mike Bayer
Alembic 0.8.5 is now available. Version 0.8.5 includes a short set of bugfixes. See http://alembic.readthedocs.org/en/latest/changelog.html#change-0.8.5. Download Alembic 0.8.5 at: https://pypi.python.org/pypi/alembic -- You received this message because you are subscribed to the Google