Re: [sqlalchemy] sqlacodegen

2020-11-10 Thread Mike Bayer
/Connecting-to-SQL-Server-from-Linux . if you can get pyodbc to connect directly we can show you the correct URL format. On Mon, Nov 9, 2020, at 11:22 PM, Larry Martell wrote: > sqlacodegen mssql+pyodbc://user:password@host/database > > On Monday, November 9, 2020 at 11:03:03 PM UTC-5 Mike Ba

Re: [sqlalchemy] sqlacodegen

2020-11-09 Thread Mike Bayer
this has to do with how you are formatting your URL, and it is being seen as a hostname and not a DSN name. can't provide any more help without seeing how you are formatting this URL as well as what is the actual method you are trying to use to connect (DSN or hostname). On Mon, Nov 9,

Re: [sqlalchemy] OverflowError: int to big to convert

2020-11-09 Thread Mike Bayer
that error is thrown by SQL Server and/or the ODBC driver you are using. make sure you are using an appropriate datatype for the column in the database. You can likely get more help on the pyodbc issue tracker at https://github.com/mkleehammer/pyodbc/issues as SQLAlchemy just passes these

Re: [sqlalchemy] SQLAlchemy array aggregate of objects

2020-11-05 Thread Mike Bayer
I think what's important here is to come up with the exact SQL string you'd like to create first, then if you can share that here we can show you how SQLAlchemy can render it from the expression language.As far as working with the PG functions someone else here might know or you can try

Re: Example of inline autogenerated use?

2020-11-05 Thread Mike Bayer
Not quite given in an example, I guess I could add as a recipe but then people will be using it which as you've noted isn't reliable in the general sense, let's put together how to get the MigrationScript, which it looks like you have, with then how to make the Operations object

Re: [sqlalchemy] Re: Joinedload from child to parent in a joined table relationship

2020-11-03 Thread Mike Bayer
yeah if any of those JOINs were LEFT OUTER joins then the combination of INNER and OUTER join would not be associative so...it right nests like that. On Tue, Nov 3, 2020, at 1:53 PM, Alex Collins wrote: > Thanks so much! I was interpreting the parenthesis as a subquery. Been > banging my head

Re: [sqlalchemy] Joinedload from child to parent in a joined table relationship

2020-11-03 Thread Mike Bayer
hey there - great test script, thanks for making this easy. using modern SQLAlchemy versions your script outputs the SELECT: SELECT source.id AS source_id FROM source JOIN (poly_parent JOIN poly_child ON poly_parent.id = poly_child.id) ON source.id = poly_child.parent_id If you are seeing a

Re: [sqlalchemy] Updating another table in "before-insert" event

2020-11-03 Thread Mike Bayer
he SQL and look at what's transpired. > > On Saturday, October 24, 2020 at 10:17:10 PM UTC+8 Mike Bayer wrote: >> >> >> >> >> On Fri, Oct 23, 2020, at 8:30 PM, ai.rese...@gmail.com wrote: >>> >>> Hi all >>> >>>

Re: [sqlalchemy] Generic File Loader issue with Booleans

2020-10-28 Thread Mike Bayer
etc On Wed, Oct 28, 2020, at 10:33 AM, Andrew Martin wrote: > I will reproduce this when I get done with work this evening and give the > specifics. > > On Wednesday, October 28, 2020 at 7:46:26 AM UTC-5, Mike Bayer wrote: >> >> >> On Tue, Oct 27, 2020, at

Re: [sqlalchemy] Generic File Loader issue with Booleans

2020-10-28 Thread Mike Bayer
On Tue, Oct 27, 2020, at 11:56 PM, Andrew Martin wrote: > This is probably a weirdly specific question, but I have a workflow that > involves loading lots of CSVs into Postgres. Some of them are very large, so > I want to cut overhead and not use CSV Dictreader. Wanted to use named tuples >

Re: [sqlalchemy] Updating another table in "before-insert" event

2020-10-24 Thread Mike Bayer
On Fri, Oct 23, 2020, at 8:30 PM, ai.rese...@gmail.com wrote: > > Hi all > > I want to update a table row once I create a new row in another table. These > 2 tables are in the same database, but no relationship between them > > I use "before_insert" listener for the first table. In this

Re: [sqlalchemy] Re: calling stored procedure 1000 times in a row - system impact?

2020-10-21 Thread Mike Bayer
you likely want to use cx_oracle directly so that you can use callproc(): https://cx-oracle.readthedocs.io/en/latest/user_guide/plsql_execution.html to access the cx_oracle cursor see the guidelines at https://docs.sqlalchemy.org/en/13/core/connections.html#calling-stored-procedures you might

Re: [sqlalchemy] Cannot insert strings with a length greater than 2000 into columns with a datatype of Text, VARCHAR, or NVARCHAR using MS SQL Server 2017 and 2019

2020-10-18 Thread Mike Bayer
th pyodbc, so maybe Mike is right about the real world use >> cases. >> >> >> >> On Sat, Oct 17, 2020 at 1:52 PM Mike Bayer wrote: >>> >>> __ >>> We also have a reproduction case and at least plans to document using the >>> new ho

Re: [sqlalchemy] Cannot insert strings with a length greater than 2000 into columns with a datatype of Text, VARCHAR, or NVARCHAR using MS SQL Server 2017 and 2019

2020-10-17 Thread Mike Bayer
t; I will drop the _SC collation until I explicitly needs in my application for > string operations, while probably will happen in the future. > > Thanks Mike and Simon for your great support. > On Friday, October 16, 2020 at 10:22:45 PM UTC+2 Mike Bayer wrote: >> >> &g

Re: [sqlalchemy] Cannot insert strings with a length greater than 2000 into columns with a datatype of Text, VARCHAR, or NVARCHAR using MS SQL Server 2017 and 2019

2020-10-16 Thread Mike Bayer
; > Simon > > On Fri, Oct 16, 2020 at 1:14 PM Mike Bayer wrote: > > > > > > > > On Fri, Oct 16, 2020, at 3:53 AM, Nicolas Lykke Iversen wrote: > > > > Is it really necessary to use your very-subtle vendored version of the > > set_input_sizes() h

Re: [sqlalchemy] postgresql JSON(B) dialect: update value of a specific key in a JSON object

2020-10-16 Thread Mike Bayer
from sqlalchemy import Column from sqlalchemy import Integer from sqlalchemy import update from sqlalchemy.dialects import postgresql from sqlalchemy.dialects.postgresql import JSONB from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class A(Base):

Re: [sqlalchemy] Text subquery column names in the results

2020-10-16 Thread Mike Bayer
them. from sqlalchemy import text, select, column user_query = 'select "FirstName", from "Customer"' stmt = text(user_query).columns(column("FirstName")) subq = stmt.alias("subq") stmt = select([subq]) stmt = stmt.distinct() stmt = stmt.order_by(subq.c.First

Re: [sqlalchemy] Cannot insert strings with a length greater than 2000 into columns with a datatype of Text, VARCHAR, or NVARCHAR using MS SQL Server 2017 and 2019

2020-10-16 Thread Mike Bayer
> a. length longer than 2000 characters. > > Best regards > Nicolas > > > > On Thursday, October 15, 2020 at 7:39:08 PM UTC+2 Mike Bayer wrote: >> >> >> On Thu, Oct 15, 2020, at 3:26 AM, Nicolas Lykke Iversen wrote: >>> Hi Mike, >>>

Re: [sqlalchemy] Cannot insert strings with a length greater than 2000 into columns with a datatype of Text, VARCHAR, or NVARCHAR using MS SQL Server 2017 and 2019

2020-10-15 Thread Mike Bayer
Session(e) s.add(A(data="some data", x=1, y=4)) s.commit() > > Can you recommend a hotfix for using varchar(max)in current SQLAlchemy > applications that need to handle Unicode supplementary characters (_SC)? > > I appreciate really appreciate your help. >

Re: [sqlalchemy] Text subquery column names in the results

2020-10-15 Thread Mike Bayer
On Thu, Oct 15, 2020, at 2:52 AM, Kotofos online wrote: > > Hi, > Could you shed some light on what I might be doing incorrectly? I have this > text() SELECT * query on top of a one-column sub-query and in the result, I > am not getting that column name. > > ``` > stmt = text('select

Re: [sqlalchemy] Cannot insert strings with a length greater than 2000 into columns with a datatype of Text, VARCHAR, or NVARCHAR using MS SQL Server 2017 and 2019

2020-10-14 Thread Mike Bayer
success') > > content = 2001 * 'A' > > cursor.execute(f""" > INSERT INTO msg (content) > VALUES ('{content}')""") > print(f'non-param: {len(content)=}: success') > > # this fails! > sql = f""" > INSERT INT

Re: [sqlalchemy] Cannot insert strings with a length greater than 2000 into columns with a datatype of Text, VARCHAR, or NVARCHAR using MS SQL Server 2017 and 2019

2020-10-13 Thread Mike Bayer
nd options are in use in that scenario. > > Best regards > Nicolas > > > On Tue, 13 Oct 2020 at 22.22, Mike Bayer wrote: >> __ >> >> >> On Tue, Oct 13, 2020, at 10:50 AM, Nicolas Lykke Iversen wrote: >>> Hi SQLAlchemy, >>> >>>

Re: [sqlalchemy] Cannot insert strings with a length greater than 2000 into columns with a datatype of Text, VARCHAR, or NVARCHAR using MS SQL Server 2017 and 2019

2020-10-13 Thread Mike Bayer
On Tue, Oct 13, 2020, at 10:50 AM, Nicolas Lykke Iversen wrote: > Hi SQLAlchemy, > > *System information:* > * Mac OS X v. 10.15.7 > * Python v. 3.8.5 > * SQLAlchemy v. 1.3.19 > * MS SQL Server 2017 and 2019 (both Enterprise and Docker images e.g. >

Re: command.init api ignores the cfg settings

2020-10-09 Thread Mike Bayer
hi there - this question lacks specifics. There are no configuration options that are relevant to the "alembic init" command in any case so it's not clear what config settings you are seeing as "ignored"; init uses only the name of the ini file given and this works: from alembic.config

Re: [sqlalchemy] question :)

2020-10-09 Thread Mike Bayer
yes the tuple construct provides this: https://docs.sqlalchemy.org/en/13/core/sqlelement.html?highlight=tuple#sqlalchemy.sql.expression.tuple_ >>> from sqlalchemy import select, column, tuple_ >>> stmt = select([column('q')]).where(tuple_(column('x'), column('y')) == >>> tuple_(3, 4)) >>>

Re: [sqlalchemy] Documentation hint

2020-10-09 Thread Mike Bayer
an error raise would be better since that's not a documentation note anyone would notice. there seems to be a more general issue that you can put any SQL elements in literal() and that should not be happening in 1.4, so lets make a real bug https://github.com/sqlalchemy/sqlalchemy/issues/5639

Re: [sqlalchemy] stream_results cursor name

2020-10-05 Thread Mike Bayer
it's not. if you want to work with named cursors in a DBAPI-specific way I would follow the guidelines at https://docs.sqlalchemy.org/en/13/core/connections.html#working-with-raw-dbapi-connections . On Mon, Oct 5, 2020, at 11:00 AM, Massimiliano della Rovere wrote: > When using

Re: [sqlalchemy] FetchedValue columns are INSERTed by Session.merge()

2020-10-02 Thread Mike Bayer
On Fri, Oct 2, 2020, at 12:15 PM, Wilson, Chris wrote: > Dear Michael and co, > > I think that Columns which are marked as server_default=FetchedValue(), which > are normally omitted from INSERT statements, are not omitted after an object > has been merged from another session. Therefore

Re: Use events with expression api

2020-09-30 Thread Mike Bayer
SQL expressions are intercepted by the SQL Execution events described at https://docs.sqlalchemy.org/en/13/core/events.html#sql-execution-and-connection-events and the main ones are before_execute() and before_cursor_execute(), but it depends on what you want to do.if you want to change how

Re: [sqlalchemy] postgresql: force create SERIAL without primary key

2020-09-30 Thread Mike Bayer
chema.py:3615: SAWarning: > > Table 'outputs' specifies columns 'id' as primary_key=True, not matching > locally specified columns 'id', 'hotel', 'run_id'; setting the current > primary key columns to 'id', 'hotel', 'run_id'. This warning may become an > exception in a future

Re: [sqlalchemy] postgresql: force create SERIAL without primary key

2020-09-30 Thread Mike Bayer
'id' as primary_key=True, not matching > locally specified columns 'id', 'hotel', 'run_id'; setting the current > primary key columns to 'id', 'hotel', 'run_id'. This warning may become an > exception in a future release > > вторник, 29 сентября 2020 г. в 21:05:47 UTC+4, Mike Bayer:

Re: [sqlalchemy] postgresql: force create SERIAL without primary key

2020-09-29 Thread Mike Bayer
set autoincrement=False in the Column definition Column('id', BIGINT, autoincrement=False) On Tue, Sep 29, 2020, at 3:49 PM, Павел Фролов wrote: > Hi all, > > I need just autoincrement without primary key, like: > > CREATE TABLE test ( > id BIGSERIAL NOT NULL, > run_id INTEGER NOT

Re: Stray changes detected only sometimes with revision --autogenerate

2020-09-29 Thread Mike Bayer
Hi, so I added a quick recipe to the site just now just so that the "set search path" idea is documented to some extent, that is at https://alembic.sqlalchemy.org/en/latest/cookbook.html#rudimental-schema-level-multi-tenancy-for-postgresql-databases . Re: autogenerate, if you have many

Re: Stray changes detected only sometimes with revision --autogenerate

2020-09-29 Thread Mike Bayer
On Tue, Sep 29, 2020, at 3:35 PM, Mike Bayer wrote: > > > On Tue, Sep 29, 2020, at 9:17 AM, Daniel Krebs wrote: >> Hi, >> >> we're having rather strange problems with Alembic 1.4.2 and Postgres 12, >> detecting stray changes *sometimes* but also sometim

Re: Stray changes detected only sometimes with revision --autogenerate

2020-09-29 Thread Mike Bayer
On Tue, Sep 29, 2020, at 9:17 AM, Daniel Krebs wrote: > Hi, > > we're having rather strange problems with Alembic 1.4.2 and Postgres 12, > detecting stray changes *sometimes* but also sometimes not. I already dug > through the code but I increasingly get the feel that this is rooted >

Re: [sqlalchemy] Re: Adapting a library to SA 1.4b1

2020-09-28 Thread Mike Bayer
I pushed the fix for that, give it another go. this is good testing you're doing as you have a lot of SQL Core metaprogramming going on. things are REALLY different on the inside :) On Sun, Sep 27, 2020, at 4:36 PM, Lele Gaifax wrote: > "Mike Bayer" writes: &

Re: [sqlalchemy] Adapting a library to SA 1.4b1

2020-09-27 Thread Mike Bayer
Hi Lele - It looks like .froms on a simple select() that is against ORM entities is just broken here, so we can fix that. at the moment it's a one liner but there are some performance implications that might make it more tricky but you can look at

Re: [sqlalchemy] Parameterized "Relationships" with Eager Loading Capability

2020-09-23 Thread Mike Bayer
d will be replaced in > the string-lookup table > On Wednesday, September 23, 2020 at 4:20:01 PM UTC-4 Mike Bayer wrote: >> __ >> yeah I don't have a solution to that problem right now, as mapped attributes >> are only a class-bound concept and there is no concept of an a

Re: [sqlalchemy] Parameterized "Relationships" with Eager Loading Capability

2020-09-23 Thread Mike Bayer
ly has different meaning. > On Wednesday, September 23, 2020 at 3:21:23 PM UTC-4 Mike Bayer wrote: >> __ >> A.bs only goes to the "bs" collection on an A. there's no eagerloading that >> puts the collection on some other arbitrary place. >> >> On Wed,

Re: [sqlalchemy] Parameterized "Relationships" with Eager Loading Capability

2020-09-23 Thread Mike Bayer
options(selectinload(A.bs).and_(B.some_field == > value).as(f'bs_filtered_by_{value}') > ... > for a in q: >for b in a.bs_filtered_by_: > > > > On Wednesday, September 23, 2020 at 12:21:41 PM UTC-4 Mike Bayer wrote: >> >> >> On Wed, Sep 23

Re: [sqlalchemy] Parameterized "Relationships" with Eager Loading Capability

2020-09-23 Thread Mike Bayer
e class > name and module name as my_app.graphql.queries.ATmp, and will be replaced in > the string-lookup table > > though it does seem to work (I am able to avoid n+1 and do the filtering in > the DB). > On Wednesday, September 23, 2020 at 8:10:44 AM UTC-4 Mike Bayer wrote:

Re: [sqlalchemy] Parameterized "Relationships" with Eager Loading Capability

2020-09-23 Thread Mike Bayer
On Wed, Sep 23, 2020, at 5:43 AM, agrot...@gmail.com wrote: > Let's say I have a model with a one to many relationship as such: > class A(Base): > id = ... > > class B(Base): > id = ... > some_field = > a_id = Column(ForeignKey(A.id)... > a = relationship(A, backref=backref('bs',

Re: [sqlalchemy] How to identify unique constraint violation without dependency on a specific database driver?

2020-09-18 Thread Mike Bayer
On Fri, Sep 18, 2020, at 3:34 PM, Vitaly Kruglikov wrote: > My table has a unique index on the column named "tag". When I attempt to > insert a row with a tag value that already exists in the table, sqlalchemy > raises the generic exception `IntegrityError`. > > `IntegrityError` may be raised

Re: [sqlalchemy] SQLAlchemy CORE: bindparam with postgresql on_conflict_do_update with a JSONB column

2020-09-15 Thread Mike Bayer
index_elements=(Settings.columns.key,), set_={"data": bindparam("timestamps", type_=JSONB)}, ) ) with e.begin() as conn: conn.execute(query, {"timestamps": {"foo": "bar"}}) On Tue, Sep 15, 2020, at 11:50 AM, Mike Bayer wr

Re: [sqlalchemy] SQLAlchemy CORE: bindparam with postgresql on_conflict_do_update with a JSONB column

2020-09-15 Thread Mike Bayer
Now I get a different error: bindparam is not json-serializable. > StatementError('(builtins.TypeError) Object of type BindParameter is not JSON > serializable'), > > Is the JSONB column not supporting lazy/bindparam-compatible "preparing" of > queries? > > Il gi

Re: [sqlalchemy] SQLAlchemy CORE: bindparam with postgresql on_conflict_do_update with a JSONB column

2020-09-15 Thread Mike Bayer
the dictionary is with column names as keys: set_={"data": bindparam("timestamps")} hope this helps On Tue, Sep 15, 2020, at 10:55 AM, Massimiliano della Rovere wrote: > Greetings, > I am using SQLAlchemy==1.3.18. > > I have an SQLAlchemy "Settings" table with a "data" column defined as: >

Re: [sqlalchemy] How to custom 'merge' behavior of a column type?

2020-09-15 Thread Mike Bayer
], ) assert list(s.query(A.data).order_by(A.id)) == [ ([1, 2, 3, 10, 11, 12, 13, 14, 15],), ([4, 5, 6, 10, 11, 12, 16, 17, 18],), ([7, 8, 9, 10, 11, 12, 19, 20, 21],), ] > Is there any other way for example to custom a ColumnType to change the > UPDATE s

Re: [sqlalchemy] How to custom 'merge' behavior of a column type?

2020-09-13 Thread Mike Bayer
you would need to accomplish this manually. existing_obj = session.query(MyClass).get(obj.id) if existing_obj is not None: existing_obj.links.extend(obj.links) obj = session.merge(obj) On Sat, Sep 12, 2020, at 3:45 AM, sonsshh wrote: > Hi, > > I'm trying to change the behavior of

Re: [sqlalchemy] Trying to understand FlushErrors when merging

2020-09-11 Thread Mike Bayer
t which I would assume is overwriting it during the flush. that is, you have an Album object on your Track, it doesn't actually make sense to change track1.album = "foo" without changing that whole object. I guess what most people would do here would be to not use natural pri

Re: [sqlalchemy] Trying to understand FlushErrors when merging

2020-09-10 Thread Mike Bayer
When you create a Track object and don't assign the primary key attributes directly, the instance key of the object is all nulls: Track.__mapper__.identity_key_from_instance(track1) (, (1, None, None, None), None) Track.__mapper__.identity_key_from_instance(track2) (, (1, None, None, None),

Re: [sqlalchemy] Relationship Based On Expression

2020-09-09 Thread Mike Bayer
figure it out. The obvious choice for dynamic stuff is @declared_attr but > that only let's me define one thing. How would I do *n* things? > > Is this a situation where __declare_last__ could help? > > > On Wed, Sep 9, 2020 at 3:55 PM Mike Bayer wrote: >> __ >

Re: [sqlalchemy] Relationship Based On Expression

2020-09-09 Thread Mike Bayer
On Wed, Sep 9, 2020, at 2:36 PM, Bobby Rullo wrote: > Hi there, > > I'm trying to create a relationship for a Mxin that is agnostic to what the > primary key of the mixed object is. > > Basically we have this: > > class TransitionBase(SurrogatePK, Model): > __abstract__ = True > >

Re: [sqlalchemy] ORM AmbiguousForeignKeysErro

2020-09-08 Thread Mike Bayer
hank you, so that go into each subclass that would have the problem. >> >> 8/28/20 2:37 PM, Mike Bayer wrote: >> > the argument you're looking for is inherit_condition: >> > >> > https://docs.sqlalchemy.org/en/13/orm/mapping_api.html#sqlal

Re: KeyError: 'sqlnotapplicable' when running alembic revision --autogenerate

2020-09-04 Thread Mike Bayer
this warning is the culprit: SAWarning: index key 'sqlnotapplicable' was not located in columns for table ‘github_active_users' I believe you should report this to the ibm_db_sa folks. https://github.com/ibmdb/python-ibmdbsa/issues you would need to share the "CREATE TABLE" statements

Re: [sqlalchemy] ORM 3 level hieracrchy

2020-09-03 Thread Mike Bayer
classes need the inherit_condition to point > to their immediate base. That does seem to remove the warning. > > On 9/3/20 9:58 AM, Mike Bayer wrote: > > you might be able to use the declared_attr __mapper__ but you would > > need to omit that erroneous inherit condition if the class is >

Re: [sqlalchemy] How can I use a composite foreign-key constraint with a "mixin" class using declarative?

2020-09-03 Thread Mike Bayer
dialect specific options are prefixed with the dialect name,e.g. "mysql_engine", so that they only take place for the dialect currently interacting with the schema object. they are ignored by any dialect that does not have that name. On Thu, Sep 3, 2020, at 10:15 AM, Simon King wrote: >

Re: [sqlalchemy] ORM 3 level hieracrchy

2020-09-03 Thread Mike Bayer
On Thu, Sep 3, 2020, at 7:24 AM, Richard Damon wrote: > I've tried taking my code and changing the ForeignKey to be to Node, and > that doesn't change the Warning. > Is the problem trying to DRY with the @declared_attr __mapper__? > > On 9/2/20 11:29 PM, Mike Bayer wrote: >

Re: [sqlalchemy] ORM 3 level hieracrchy

2020-09-02 Thread Mike Bayer
gt; class Property(Node): > node_id = Column(Integer, ForeignKey('Node.node_id'), primary_key=True) > ref_id = Column(Integer, ForeignKey('Node.node_id')) > > class Name(Property): > node_id = Column(Integer, ForeignKey('Property.node_id'), > primary_key=True

Re: [sqlalchemy] ORM 3 level hieracrchy

2020-09-02 Thread Mike Bayer
there's an FAQ entry, a little bit dated but the general idea is still there, at: https://docs.sqlalchemy.org/en/13/faq/ormconfiguration.html#i-m-getting-a-warning-or-error-about-implicitly-combining-column-x-under-attribute-y for joined table inheritance, where Name(Node) -> node_id are FK ->

Re: [sqlalchemy] ORM AmbiguousForeignKeysErro

2020-08-28 Thread Mike Bayer
the argument you're looking for is inherit_condition: https://docs.sqlalchemy.org/en/13/orm/mapping_api.html#sqlalchemy.orm.mapper.params.inherit_condition class Foo(...): __mapper_args__ = { "inherit_condition": node_id == Node.node_id } On Fri, Aug 28, 2020, at 1:45 PM, Richard

Re: [sqlalchemy] How can I use a composite foreign-key constraint with a "mixin" class using declarative?

2020-08-28 Thread Mike Bayer
__table_args__ don't merge automatically right now for mixins so you would need to use a __table_args__ function with @declared_attr and merge the constraints manually. see

Re: [sqlalchemy] How to do a case-insensitive query for association proxy attributes?

2020-08-27 Thread Mike Bayer
On Thu, Aug 27, 2020, at 2:27 PM, Jacob Pavlock wrote: > I have two classes, a Track and an Album. In order to have album fields > easily accessible from a track, I created an association proxy attribute. > > ```python > class Track(MusicItem, Base): > __tablename__ = "tracks" > > _id

Re: [sqlalchemy] declared_attr not working with Postgres HSTORE

2020-08-22 Thread Mike Bayer
and how the error is produced. Within the SQLAlchemy team it's not a good use of our time to try to guess what it is someone is trying to do so we ask that users illustrate everything up front to reproduce the error. thanks! > On Saturday, August 22, 2020 at 9:30:11 AM UTC-7 Mike Ba

Re: [sqlalchemy] declared_attr not working with Postgres HSTORE

2020-08-22 Thread Mike Bayer
; On Saturday, August 22, 2020 at 9:19:19 AM UTC-7 Mike Bayer wrote: >> __ >> Hi, I have no idea what the problem is and would need a fully runnable MCVE. >> Below is part of your test which I've tried to get running but it still >> errors out on identifiers missing and su

Re: [sqlalchemy] declared_attr not working with Postgres HSTORE

2020-08-22 Thread Mike Bayer
many Column objects with the same name and different types, all against a single table. That's not possible in relational databases. On Sat, Aug 22, 2020, at 12:18 PM, Mike Bayer wrote: > Hi, I have no idea what the problem is and would need a fully runnable MCVE. > Below is part of your te

Re: [sqlalchemy] ArgumentError: Only one Column may be marked autoincrement=True, found both id and id.` when I run the following insert

2020-08-22 Thread Mike Bayer
= "model1" id_ = synonym("id") tag = Column(String()) On Sat, Aug 22, 2020, at 12:14 PM, Mike Bayer wrote: > Hi Im not able to reproduce this, though I will grant things dont seem to > work very well in this area, would need to know *exactly* what it is you are

Re: [sqlalchemy] declared_attr not working with Postgres HSTORE

2020-08-22 Thread Mike Bayer
Hi, I have no idea what the problem is and would need a fully runnable MCVE. Below is part of your test which I've tried to get running but it still errors out on identifiers missing and such, additionally I need a working example of exactly the session operations you are trying to achieve.

Re: [sqlalchemy] ArgumentError: Only one Column may be marked autoincrement=True, found both id and id.` when I run the following insert

2020-08-22 Thread Mike Bayer
Hi Im not able to reproduce this, though I will grant things dont seem to work very well in this area, would need to know *exactly* what it is you are trying to accomplish. please alter the MCVE below to reproduce your error, it passes for me however does have a warning: from sqlalchemy import

Re: [sqlalchemy] Download documentation as pdf

2020-08-21 Thread Mike Bayer
it's not, as PDF generation is very problematic and we are not able to provide this file. The sphinx documentation can be built as LaTeX that can then be converted to pdf but you'd find it's a very error prone process, and the resulting PDF doesn't look very good either. On Fri, Aug 21, 2020,

Re: [sqlalchemy] Table to track applied migrations?

2020-08-19 Thread Mike Bayer
this is issue 309 https://github.com/sqlalchemy/alembic/issues/309 waiting for someone with the time and motivation to work on it. On Wed, Aug 19, 2020, at 11:25 AM, Jasen Jacobsen wrote: > I've used Liquibase in the past and as part of its migration tracking it > creates a table which lists

Re: [sqlalchemy] Getting column data from result set with column name as a string.

2020-08-19 Thread Mike Bayer
the one I want for each row because > columns doesn't have an index either. I also don't like using a private > property but I guess (hope) __table__ would always be there. > On Tuesday, August 18, 2020 at 6:05:49 PM UTC-5 Mike Bayer wrote: >> >> >> On Tue, Aug 18, 2020, at

Re: [sqlalchemy] Getting column data from result set with column name as a string.

2020-08-18 Thread Mike Bayer
On Tue, Aug 18, 2020, at 5:20 PM, Dale Preston wrote: > I'm using sqlalchemy 1.3.18. I'm trying to write an app that looks at data > from an ORM declarative table without necessarily knowing the table > definition. > > What I am looking for is a way to get a single object (row in resultSet),

Re: [sqlalchemy] `Base.prepare()` doesn't backfill missing columns and relationships in AutomapBase-derived models

2020-08-18 Thread Mike Bayer
your reflect() call requires extend_existing=True in this case otherwise existing Table objects as the one you are creating with SqaGlobalContext will not be affected. On Tue, Aug 18, 2020, at 1:59 PM, Vitaly Kruglikov wrote: > Dear all, > > I am using: > sqlalchemy==1.3.18 > psycopg2==2.8.4

Re: Delay between consecutive SQL statements when using Alembic on Jenkins

2020-08-17 Thread Mike Bayer
On Sun, Aug 16, 2020, at 11:10 PM, Michał Guzek wrote: > I have a problem with delays between consecutive SQL statements when Alembic > executes a migration script's upgrade() function on Jenkins: > def upgrade(): > op.execute("DELETE FROM employee WHERE name='John';") #John also has its >

Re: [sqlalchemy] Triggers broken after move from PyPy to CPython

2020-08-13 Thread Mike Bayer
Would be very strange but the main difference between pypy and cpython is the garbage collection in cPython is usually immediate for an object withotu reference cycles whereas in Pypy it's not immediate. If this example were in a test suite where the "B" table were created in a transient way

Re: [sqlalchemy] helper function to get and/or update the InstrumentedList from a relationship on a model

2020-08-12 Thread Mike Bayer
getattr() is the most direct way but you can also use mapper.all_orm_descriptors[property_name] On Wed, Aug 12, 2020, at 11:49 AM, Mark Aquino wrote: > I was interested in creating a generic helper function to get the > instrumented list associated with a "RelationshipProperty" for a Model, >

Re: [sqlalchemy] Update multiple rows in SQLite Databse

2020-08-11 Thread Mike Bayer
since you need to track removals also I would likely keep track of individual data manipulation operations on the data from the point that it's loaded til the point that it's persisted again. The SQLAlchemy ORM's "unit of work" does exactly this, in fact, so if you loaded 25 Ingredient

Re: [sqlalchemy] Dynamically creating relationships from polymorphic subclasses to one class

2020-08-07 Thread Mike Bayer
> accordingly)? yeah that would be fine, the other way to approach it is to use more of a dynamic table format but that is not as easy to query. it sounds like you are building a star schema? https://en.wikipedia.org/wiki/Star_schema > > On Thu, Aug 6, 2020 at 4:59 PM Mike Bayer w

Re: [sqlalchemy] Dynamically creating relationships from polymorphic subclasses to one class

2020-08-06 Thread Mike Bayer
stats1month_id AS >> met_blvmetstats1month_id >> FROM met >> WHERE met.date >= ? AND met.date < ? AND met.type IN (?)] >> [parameters: ('2020-06-01 00:00:00.00', '2020-06-01 01:00:00.00', >> 'BLVMET')] >> (Background on this error at:

Re: [sqlalchemy] How to disable the integer col + pk = serial behaviour?

2020-08-05 Thread Mike Bayer
essentially means, “don’t create this sequence on the PostgreSQL backend, where the SERIAL keyword creates a sequence for us automatically”. On Wed, Aug 5, 2020, at 9:21 PM, Mike Bayer wrote: > > > On Wed, Aug 5, 2020, at 7:54 PM, zsol...@gmail.com wrote: >> Thanks for all

Re: [sqlalchemy] How to disable the integer col + pk = serial behaviour?

2020-08-05 Thread Mike Bayer
his essentially means, "don't create the sequence on PostgreSQL, use SERIAL instead". This dynamic is going to be changing soon as most of these databases are now supporting the GENERATED AS IDENTITY syntax and we'll be adding support for that in 1.4. > > Zsolt > > &g

Re: [sqlalchemy] How to disable the integer col + pk = serial behaviour?

2020-08-05 Thread Mike Bayer
le table. > > So far the only solution I found is to remove primary_key=True and > issue an ALTER TABLE ... ADD PRIMARY KEY (...) command manually. > > > > On Wed, 5 Aug 2020 at 15:20, Mike Bayer wrote: > > > > > > > > On Wed, Aug 5, 2020, at 8:59

Re: [sqlalchemy] Re: How to disable the integer col + pk = serial behaviour?

2020-08-05 Thread Mike Bayer
On Wed, Aug 5, 2020, at 9:07 AM, Zsolt Ero wrote: > I'm lost in two places: > > sa.Column( > 'trip_num', > sa.Integer, > sa.Sequence('trip_num_seq', schema='public', optional=True), > primary_key=True, > ) > > > 1. I'm specifying schema='public', yet the sequence gets created under >

Re: [sqlalchemy] How to disable the integer col + pk = serial behaviour?

2020-08-05 Thread Mike Bayer
On Wed, Aug 5, 2020, at 8:59 AM, Zsolt Ero wrote: > Hi, > > I've split a table into two tables, for performance reasons. I'd like to > insert into both tables using the same sequence. I'm inserting using > executemany_mode='values'. > > My idea is to call nextval() on the sequence before

Re: [sqlalchemy] Dynamically creating relationships from polymorphic subclasses to one class

2020-08-01 Thread Mike Bayer
hi and thanks for the straightforward test case. I'm not sure if that's an old version of SQLAlchemy you're using, when I run with current 1.3.18 release the error message is more descriptive: "Could not determine join condition between parent/child tables on relationship ACollection.members -

Re: [sqlalchemy] Warning about CTE, aliased classes and update

2020-07-27 Thread Mike Bayer
hi - the ORM update() function wants to locate all occurrences of MonitorJournal that are locally present in the Session in question which match the WHERE criteria in use, and then it wants to alter those instances with the newly updated value in memory, so that in order for the effects of the

Re: [sqlalchemy] Befuddled with FK, ondelete, and delete cascade

2020-07-26 Thread Mike Bayer
in the backref you have to tell it that the ORM should expect child rows to be deleted, and also that FK cascade setting in the database will accommodate the operation, using cascade="all, delete-orphan" as well as passive_deletes=True. the docs for this are at

Re: [sqlalchemy] Many-to-many using custom join columns and autoloaded tables

2020-07-21 Thread Mike Bayer
to join on the relationships you have to name them: Class.query.join(Class.enrollments).join(Enrollment.students).join(Student.details) the different ways to join are laid out at https://docs.sqlalchemy.org/en/13/orm/query.html?highlight=query%20join#sqlalchemy.orm.query.Query.join On Tue,

Re: [sqlalchemy] Thread Safety

2020-07-21 Thread Mike Bayer
On Mon, Jul 20, 2020, at 7:55 PM, Praveen Kumar wrote: > > Confirming some details re: thread safety ( I noticed older posts in this > group on the topic... but they're quite old ) -- > > I'm using version 1.2.7, and can't upgrade. I understand that Connection and > Transaction are not

Re: [sqlalchemy] What's the difference between the two syntax of declaring index?

2020-07-17 Thread Mike Bayer
On Fri, Jul 17, 2020, at 7:20 AM, Bob Fang wrote: > Hi I have seen two/three ways to declare index on table: > > 1. use index=True > > class Model(Base): > __tablename__ = "model" > id = sa.Column(sa.Integer, primary_key=True) > field_1 = sa.Column(sa.Integer, index=True) > > 2.

Re: [sqlalchemy] Remap an SQLAlchemy instance to a different non-SQLAlchemy class

2020-07-10 Thread Mike Bayer
hey there - what you're doing is suited by an included feature of SQLAlchemy called "single table inheritance", which will return to you instances of "Mammal" or AnimalModel object based on the value of "type". see:

Re: [sqlalchemy] Encrypt/Decrypt specific column(s)

2020-07-10 Thread Mike Bayer
rypt("some value") b'7884f37e601994409b34618ca6a41606' (Pdb) aes_encrypt("some value") b'7884f37e601994409b34618ca6a41606' On Fri, Jul 10, 2020, at 11:16 AM, Mike Bayer wrote: > The recipe encrypts the value in the WHERE clause, however it seems like the > usage of the libraries in the e

Re: [sqlalchemy] Encrypt/Decrypt specific column(s)

2020-07-10 Thread Mike Bayer
_value = 'secrets').first() > > Returns None even though I have an encrypted value of "secrets" in that > column. > Any idea what I could be doing wrong? > > On Thursday, 9 July 2020 16:37:17 UTC+2, Mike Bayer wrote: >> >> >> On Thu, Jul 9, 2020, at 4:53 AM

Re: [sqlalchemy] sqlalchemy messes up names with "_1" suffix

2020-07-10 Thread Mike Bayer
On Fri, Jul 10, 2020, at 8:50 AM, Xander Cage wrote: > hi, > > i have this litte flask-admin game running, now out of nowwhere sqlalchemy > has begun to add strange "_1" suffixes to the column names. i know sqlalchemy > does this to keep names unique, but in my case the queries are failing >

Re: [sqlalchemy] postgresql geometry types

2020-07-09 Thread Mike Bayer
Hi - I think you want to be using geoalchemy2: https://geoalchemy-2.readthedocs.io/en/latest/ On Wed, Jul 8, 2020, at 3:37 PM, Роберт Шотланд wrote: > We are beginning to use the PostgreSQL (12) geometric types (initially the > 'point' datatype) in our SA model, and was disappointed to find

Re: [sqlalchemy] Encrypt/Decrypt specific column(s)

2020-07-09 Thread Mike Bayer
rk for any modern version in the past five years at least > So with this, I would be able to query/filter an encrypted column and it will > automatically perform the decryption to test the column? should work, sure, try it out > > > On Wednesday, 8 July 2020 at 16:10:22 UTC

Re: [sqlalchemy] Encrypt/Decrypt specific column(s)

2020-07-08 Thread Mike Bayer
I had just created all-new revised encryption examples on the wiki and apparently I forgot to link them from the index, fixed. Here's two examples showing the general idea of how this can be done: https://github.com/sqlalchemy/sqlalchemy/wiki/SymmetricEncryptionClientSide

Re: [sqlalchemy] Attaching a second database to a connection

2020-07-07 Thread Mike Bayer
es, then yes, you need to emit CREATE TABLE for all of those. SQLAlchemy isn't doing anything automatic here it just emits the SQL commands you tell it to, so at the general level think of this as working with the sqlite3 module directly, just that you have a tool to help you write some of

Re: [sqlalchemy] Attaching a second database to a connection

2020-07-06 Thread Mike Bayer
On Mon, Jul 6, 2020, at 11:19 PM, Richard Damon wrote: > SQLite allows a program to attach multiple databases to a single > connection, and you are able to reference tables in these additional > databases with things like schema.table as the name of a table. > > Is there a way to do this in

Re: [sqlalchemy] SQLAlchemy taking too much time to process the result

2020-07-06 Thread Mike Bayer
On Mon, Jul 6, 2020, at 2:14 PM, Saylee M. wrote: > Hello all, > Hope you are fine and safe in these times! > > I can be easily considered as a novice in SQLAlchemy. > I am trying to pull data from a MYSQL database from a table having around 20 > columns and more than 10 million rows. > The

<    1   2   3   4   5   6   7   8   9   10   >