Re: [sqlalchemy] How correct sort items by @hibrid_property

2023-10-30 Thread Simon King
func.sum" to calculate a sum over the related rows. For your purposes, you probably want "func.avg" to calculate the mean. (Note that the performance of this query is going to get worse as the number of products and ratings increases) Hope that helps, Simon On Sun, Oct 29, 2023 a

Re: [sqlalchemy] Difference b/w creating a DeclarativeBase class vs assigning DeclarativeBase()

2023-10-10 Thread Simon King
, the preferred form is: from sqlalchemy.orm import DeclarativeBase class Base(DeclarativeBase): pass The new approach works better with type-analysis tools like mypy. https://docs.sqlalchemy.org/en/20/changelog/whatsnew_20.html#whatsnew-20-orm-declarative-typing Hope that helps, Simon

Re: [sqlalchemy] Issuing Raw SQL and Returning a List of Objects

2023-08-23 Thread Simon King
(with Alembic for migrations as the schema changed over time). SQLAlchemy also gives a certain amount of independence from the underlying database, meaning that I can run most of my tests using SQLite despite using Postgres or MySQL in production. In summary: use the right tool for the job :-) Simon

Re: [sqlalchemy] Change a select clause + add a join automatically

2023-04-20 Thread Simon King
to be able to use the event hook to add a loader criteria option targeting the appropriate translation. Simon On Tue, Apr 11, 2023 at 5:13 PM Nishant Varma wrote: > Hello, > > I have this schema: > > class Question(Base): > __tablename__ = "question" > idn = C

Re: [sqlalchemy] Queries Across 13 Models - How to improve efficiency?

2023-01-27 Thread Simon King
instances = dbsession.query(*models).filter(*conditions).first() instancedict = {i.__table__.name: i for i in instances} Hope that helps, Simon On Thu, Jan 26, 2023 at 3:05 PM Shuba wrote: > Hi! > I have a web application whose main feature is to query 13 different > database tables whe

Re: [sqlalchemy] Breaking Integration with Locust Tests? Having a hard time debugging

2022-11-07 Thread Simon King
the unreleased version of sqlalchemy-utils, or downgrade SQLAlchemy to a non-beta version. Hope that helps, Simon On Fri, Nov 4, 2022 at 11:22 PM 'Theo Chitayat' via sqlalchemy < sqlalchemy@googlegroups.com> wrote: > I have a model that uses ChoiceType like an enum for my FastAPI app.

Re: [sqlalchemy] iterate sqlalchemy query over for loop in my template python-flask

2022-10-27 Thread Simon King
I can't see anything obviously wrong with your code. If you turn on debug logs, you'll be able to see the SQL that is being executed, and the rows that are coming back. Paste those logs here and maybe we'll be able to help more. Simon On Tue, Oct 25, 2022 at 2:38 PM Abdellah ALAOUI ISMAILI

Re: [sqlalchemy] iterate sqlalchemy query over for loop in my template python-flask

2022-10-25 Thread Simon King
for those tags? Simon On Sat, Oct 22, 2022 at 3:37 PM Abdellah ALAOUI ISMAILI < my.alaoui...@gmail.com> wrote: > wheel ... in my template, I get just the first tag color, returned from > the function. > > this is the result of my HTML file source code : > > >

Re: [sqlalchemy] iterate sqlalchemy query over for loop in my template python-flask

2022-10-21 Thread Simon King
utput from the template? Simon On Thu, Oct 20, 2022 at 9:05 AM Abdellah ALAOUI ISMAILI < my.alaoui...@gmail.com> wrote: > Hello, > I call a function in my template that returns sqlalchemy query result, > (color value from the name of the tag). this is the query function : &g

Re: [sqlalchemy] Can’t make the Composite Comparator work…

2022-09-16 Thread Simon King
of the comparator_factory is to add class-level behaviour when you are building SQL expressions. In this case, you could write a query like this: query = dbsession.query(Vertex).filter(Vertex.start > Point(2, 2)) Hope that helps, Simon On Fri, Sep 16, 2022 at 9:38 AM jens.t...@gmail.com wr

Re: [sqlalchemy] Just starting with sqlacodegen: wrong command?

2022-06-15 Thread Simon King
alenv, by using an absolute path. Hope that helps, Simon On Tue, Jun 14, 2022 at 5:32 PM Javier Garcia wrote: > This is what I'm getting when I try to upgrade to 3.0.0b3. > > (venv) jgarcia@Javier-PC:/var/www$ sudo pip install sqlacodegen==3.0 > ERROR: Could not find a version th

Re: [sqlalchemy] Just starting with sqlacodegen: wrong command?

2022-06-14 Thread Simon King
Based on the CHANGES file, it looks like --generator is a new option in v3.0.0: https://github.com/agronholm/sqlacodegen/blob/master/CHANGES.rst Simon On Tue, Jun 14, 2022 at 5:06 PM Javier Garcia wrote: > Hi, > > I have tried to run something like this: > > sqlacodegen --g

Re: [sqlalchemy] simple query takes to long

2022-06-09 Thread Simon King
How many rows are you fetching, and how many columns in each row? On Thu, Jun 9, 2022 at 8:37 AM Trainer Go wrote: > Hello Jonathan, > > i already executed the query without using pandas in my programm > > query = "SELECT" > for row in conn.execute(query).fetchall(): > pass > > the result

Re: [sqlalchemy] how i can avoid the existing database table while generating the initial revision using alembic

2022-06-08 Thread Simon King
print("Returning %s" % result) return result Use that hook in your env.py and regenerate your migration script. You should see output for each object in the database. Simon On Wed, Jun 8, 2022 at 5:59 PM Vishal Shimpi wrote: > Thank you Simon for your response. yes i am usin

Re: [sqlalchemy] how i can avoid the existing database table while generating the initial revision using alembic

2022-06-08 Thread Simon King
Names from the Autogenerate Process") is probably what you want. Hope that helps, Simon On Wed, Jun 8, 2022 at 3:15 PM Vishal Shimpi wrote: > I am working on fastapi, in which i have created models and i am inteded > to create the table in sql server database, however when i am runing

Re: [sqlalchemy] Does alembic support multiple databases?

2022-05-13 Thread Simon King
and pass the environment name on the command line: https://alembic.sqlalchemy.org/en/latest/api/runtime.html#alembic.runtime.environment.EnvironmentContext.get_x_argument Hope that helps, Simon On Mon, May 9, 2022 at 8:57 PM thavha tsiwana wrote: > wondering if there is more cleare

Re: [sqlalchemy] Session management for general functions within a class

2022-04-29 Thread Simon King
new_obj to both of them, which is going to be a problem. If it were me, I would explicitly pass the session to the move_to_error method. If you don't like that, you can also use sqlalchemy.orm.object_session to get the session that new_obj already belongs to. Hope that helps, Simon On Fri, Apr

Re: [sqlalchemy] query many-many with asssociation table

2022-04-06 Thread Simon King
I think it should work if you join to the *relationship* explicitly ie. session.query(User).join(User.user_groups).filter(...) Hope that helps, Simon On Tue, Apr 5, 2022 at 9:48 PM Jason Hoppes wrote: > I want to select all users in a particular group. I have a users table, > user_

Re: [sqlalchemy] do_connect listener called couple of times

2022-03-23 Thread Simon King
conn1: do_connect cargs: [] cparams: {'host': 'db', 'db': 'db', 'user': 'user', 'passwd': 'correct', 'client_flag': 2} conn2: As you can hopefully see, the first connection attempt triggered an exception. The correct password was then stored in cparams, and the next time we called engine.co

Re: [sqlalchemy] do_connect listener called couple of times

2022-03-22 Thread Simon King
call to the handler will contain the new value. If each task invocation is creating a new engine using a connection string that is out of date, then none of that will help you, but that would be an Airflow problem, not an SQLAlchemy problem. Simon On Mon, Mar 21, 2022 at 8:27 PM Srinu Chp wrote: &

Re: [sqlalchemy] do_connect listener called couple of times

2022-03-21 Thread Simon King
["password"] = get_new_password() return cx_Oracle.connect(*args, **cparams) Hope that helps, Simon On Mon, Mar 21, 2022 at 4:26 PM Srinu Chp wrote: > > Hello Simon, > > Thank you for prompt response. I really appreciate your help. I am trying to > achieve password rota

Re: [sqlalchemy] do_connect listener called couple of times

2022-03-21 Thread Simon King
r "do_connect" event, and so on. I'm surprised the application gets as far as it does. Maybe the exception handler inside receive_do_connect is allowing it to stumble on. Simon On Mon, Mar 21, 2022 at 4:51 AM Srinu Chp wrote: > > Hello Team, > > I tried to create a stand

Re: [sqlalchemy] None! Can't pickle : it's not the same object as sqlalchemy.orm.session.Session

2022-03-16 Thread Simon King
the instance from the database itself, or b) Send simpler (non-SQLAlchemy) objects to the worker, Hope that helps, Simon On Wed, Mar 16, 2022 at 2:34 AM Haris Damara wrote: > > Hi, > > Please help. > > Find issue with error message "None! Can't pickle 'sqlalchemy.orm.session.Sessi

Re: [sqlalchemy] Issue "translating" raw SQL to SQLAlchemy ORM query

2022-02-25 Thread Simon King
/en/14/orm/loading_relationships.html#using-contains-eager-to-load-a-custom-filtered-collection-result Hope that helps, Simon On Wed, Feb 23, 2022 at 5:19 PM shuhari2020 wrote: > > FROM: > https://stackoverflow.com/questions/71225408/issue-translating-raw-sql-to-sqlalchemy-orm-query > > I have the fo

Re: [sqlalchemy] What is the best way to declare a table with 260 columns and add rows on that table

2022-02-25 Thread Simon King
ike this: https://docs.sqlalchemy.org/en/14/orm/mapping_styles.html#imperative-a-k-a-classical-mappings import sqlalchemy.orm as asorm mapper_registry = saorm.registry(metadata) class Res: pass mapper_registry.map_imperatively(Res, res_table) # Now Res will have properties fo

Re: [sqlalchemy] What is the best way to declare a table with 260 columns and add rows on that table

2022-02-24 Thread Simon King
Before we do that, you said that you tried pandas dataframe.to_sql but it didn't work - can you explain what you mean? Did it raise an error, or produce the wrong result, or something else? Simon On Wed, Feb 23, 2022 at 9:13 PM janio mendonca junior wrote: > > Hi Simon, > > Thank

Re: [sqlalchemy] What is the best way to declare a table with 260 columns and add rows on that table

2022-02-23 Thread Simon King
/tutorial.html#executing-multiple-statements Hope that helps, Simon On Wed, Feb 23, 2022 at 8:42 PM janio mendonca junior wrote: > > Hi all, > > I have a inquiry from my job to create 2 tables related one-to-one and insert > some rows on the table. I have a .CSV with the data dictionary

Re: [sqlalchemy] Remove/Filter a query.all() results, add a 'virtual' column

2022-02-21 Thread Simon King
attributes foreground = "#000" background = "#fff" Now every BLPart instance will have "foreground" and "background" attributes with those values. If you need something more complicated than that, let us know how you would want to use them. Hope that hel

Re: [sqlalchemy] SQL expression object expected, got object of type instead

2022-02-01 Thread Simon
Never mind. This problem is solved by join operations. Thanks for your attention. On Friday, January 28, 2022 at 4:16:05 AM UTC+13 Simon King wrote: > I'm sorry, I still don't understand - what do you expect > query(Genome.attributes) to do? Can you give an example? > > Thank

Re: [sqlalchemy] SQL expression object expected, got object of type instead

2022-01-27 Thread Simon King
I'm sorry, I still don't understand - what do you expect query(Genome.attributes) to do? Can you give an example? Thanks, Simon On Wed, Jan 26, 2022 at 11:30 PM Simon wrote: > > Sorry for that the question is not clear. The question is how can we query a > database's property.

Re: [sqlalchemy] SQL expression object expected, got object of type instead

2022-01-25 Thread Simon King
understand what you are trying to do with it. Thanks, Simon On Mon, Jan 24, 2022 at 2:03 AM Simon wrote: > > Hi there, > > I got a problem about 'sqlalchemy.exc.ArgumentError: SQL expression object > expected, got object of type instead' > > My SQLAlchemy version is 1.3.22. I

[sqlalchemy] SQL expression object expected, got object of type instead

2022-01-23 Thread Simon
Hi there, I got a problem about 'sqlalchemy.exc.ArgumentError: SQL expression object expected, got object of type instead' My SQLAlchemy version is 1.3.22. I have a database like Class Genome: id = Column(Integer, primary_key=True) created_date = Column(Datetime, nullable=False)

Re: [sqlalchemy] Re: How to add the index_elements to the on_conflict_do_update() method

2021-12-08 Thread Simon King
age_symbol", does it show the primary key and/or unique index? Simon On Tue, Dec 7, 2021 at 10:27 PM Chaozy Z wrote: > > I also tried to add unique=True to the column message_id but still fail with > the same error > > On Tuesday, 7 December 2021 at 22:21:49 UTC Chaozy Z wrote: >&

Re: [sqlalchemy] raise error on insert/update PK?

2021-11-19 Thread Simon King
You ought to be able to use the "sqlalchemy.func" system: https://docs.sqlalchemy.org/en/14/core/tutorial.html#functions server_default=sa.func.gen_random_uuid() Hope that helps, Simon On Fri, Nov 19, 2021 at 6:21 AM jens.t...@gmail.com wrote: > > Tim, > > I want

Re: [sqlalchemy] Re: SqlAlchemy with Postgres: How can I make a query that checks if a string is in a list inside a json column

2021-10-19 Thread Simon King
rator.has_key https://github.com/sqlalchemy/sqlalchemy/blob/main/lib/sqlalchemy/dialects/postgresql/json.py#L33 Simon On Mon, Oct 18, 2021 at 10:35 PM Jonathan Vanasco wrote: > > I'm not sure, but AFAIK, this type of search isn't *easily* doable in > PostgreSQL. The json and json

Re: [sqlalchemy] Using SQLAlchemy to check if column is in numeric ranges

2021-08-31 Thread Simon King
this: ranges = [(18, 25), (40, 55), (60, 70)] conditions = [User.age.between(lower, upper) for (lower, upper) in ranges] condition = sqlalchemy.or_(*conditions) users = session.query(User).filter(condition).all() Hope that helps, Simon On Tue, Aug 31, 2021 at 10:07 AM chat...@gmail.com wrote:

Re: [sqlalchemy] Join multiple tables with association tables

2021-08-10 Thread Simon King
.text) ) # Note that this only outputs Info objects that have at least one # text object associated with them. If you want to include Info # objects without a related Text object, change the # ".join(Info.text)" to ".outerjoin(Info.text)" for (info, text)

Re: [sqlalchemy] prevent (raise exceptions) on bytestring values for non-byte types

2021-07-30 Thread Simon King
an "AttributeEvents.set" listener for each one. This should flag the error when a bytestring is assigned to a mapped attribute. Hope that helps, Simon On Fri, Jul 30, 2021 at 5:10 PM 'Jonathan Vanasco' via sqlalchemy wrote: > > Mike, thanks for replying but go back to vacation. > > Anyone el

Re: [sqlalchemy] In the onupdate function, how to get the value of the row of records to be updated

2021-06-21 Thread Simon King
/events.html#sqlalchemy.orm.MapperEvents.before_update Hope that helps, Simon On Sun, Jun 20, 2021 at 5:37 PM peizhi qin wrote: > > I have a table ,the definition is as follows: > class TEnterprise(Base): > __tablename__ = 't_enterprise' > __table_args__ = ( > {'mysql_engine': 'InnoD

Re: [sqlalchemy] Revert multiple commits using a savepoint

2021-06-21 Thread Simon King
tion”, which was essentially a block that would prevent the Session.commit() method from actually committing. """ Simon On Sat, Jun 19, 2021 at 4:27 PM kaboo HD wrote: > > > I am trying to test an endpoint in flask and I need to "refresh" the DB after > some comm

Re: [sqlalchemy] Common datetime call

2021-06-18 Thread Simon King
unction Hope that helps, Simon -- 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 recei

Re: [sqlalchemy] versioned_history example uses deprecated Column.copy() method

2021-06-17 Thread Simon King
Thanks Mike, I'll see what I can do. Simon On Wed, Jun 16, 2021 at 1:26 PM Mike Bayer wrote: > > HI Simon - > > I believe that example for now should vendor its own "copy()" function that > does what's needed. the function that's there is already un-doing some of &

[sqlalchemy] versioned_history example uses deprecated Column.copy() method

2021-06-16 Thread Simon King
deprecated) Thanks a lot, Simon -- 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. --- Yo

Re: [sqlalchemy] checking in

2021-06-15 Thread Simon King
You can see the archives at https://groups.google.com/g/sqlalchemy to get an idea of the traffic. Simon On Mon, Jun 14, 2021 at 10:25 PM Rich Shepard wrote: > > I've not worked with SQLAlchemy for several years but now want to use it in > a couple of applications. I've not seen

Re: [sqlalchemy] Postgresql JSON object update.

2021-05-24 Thread Simon King
You can use the "op" method: https://docs.sqlalchemy.org/en/14/core/sqlelement.html#sqlalchemy.sql.expression.Operators.op some_column.op("||")(other_column) Hope that helps, Simon On Mon, May 24, 2021 at 4:12 PM Massimiliano della Rovere wrote: > > In postgresql t

Re: [sqlalchemy] How to use user defined python function inside a sqlalchemy filter?

2021-05-07 Thread Simon King
o postprocess the query results in python instead, like this: a = session.query(GeneralBeqReq)\ .filter(GeneralBeqReq.c.BeqReqStatus == 1)\ .all() a = [obj for obj in a if obj.is_id_valid] Simon On Wed, May 5, 2021 at 4:28 PM Yaakov Bressler wrote: > > Query w

Re: [sqlalchemy] How to use user defined python function inside a sqlalchemy filter?

2021-04-28 Thread Simon King
the sort of validation that is_id_valid needs to do, we might be able to help more. Simon On Wed, Apr 28, 2021 at 6:33 AM Gyanaranjan Nayak wrote: > > I have a function with name is_id_valid(id) which returns either True or > False. > > I want to pass this function inside a s

Re: Re[4]: [sqlalchemy] Invertinace mapped type_id to fix value for each child class

2021-04-13 Thread Simon King
I probably wouldn't use this: if test_type == ChildClass1().typ_id: ...simply because creating an instance of the object just to get access to the typ_id seems like a waste of effort. If you really need to check integer typ_id values, the staticmethod approach seems fine. Simon On Mon, Apr

Re: Re[2]: [sqlalchemy] Invertinace mapped type_id to fix value for each child class

2021-04-12 Thread Simon King
ektTyp(id=2, name="child1") child1 = ChildObjekt1(text="child 1 text") child2 = ChildObjekt2(text="child 2 text") session.add_all([child1type, child2type, child1, child2]) session.flush() for obj in session.query(Objekt): print(obj) Simon O

Re: [sqlalchemy] Invertinace mapped type_id to fix value for each child class

2021-04-12 Thread Simon King
typ_id } And this in the subclass: __mapper_args__ = { 'polymorphic_identity': 7, } ...and you should get rid of the typ_id function and the "Objekt.typ_id = ChildClass.typ_id" line. Does that work for you? Simon On Mon, Apr 12, 2021 at 5:18 PM 'Sören Textor' via sqlalchemy

Re: [sqlalchemy] Injecting User info into _history table to track who performed the change

2021-03-24 Thread Simon King
n_history and the process_history tables, and that the "accountable" column is set correctly. I hope that makes sense, Simon On Wed, Mar 24, 2021 at 2:25 PM JPLaverdure wrote: > > Hi Simon, > > Thanks for pointing out the collision, it kinda flew under the radar ! > I renamed the co

Re: [sqlalchemy] Injecting User info into _history table to track who performed the change

2021-03-24 Thread Simon King
which can't work. If you use a different column name to store the user in the history table, does the warning go away? Simon On Tue, Mar 23, 2021 at 7:17 PM JPLaverdure wrote: > > It seems I lost my previous email.. Here it is again: > > Sure ! > Here are 2 classes for which th

Re: [sqlalchemy] Injecting User info into _history table to track who performed the change

2021-03-23 Thread Simon King
; > Thanks !! > On Monday, March 15, 2021 at 4:33:40 p.m. UTC-4 Jonathan Vanasco wrote: >> >> Going beyond what Simon did.. >> >> I typically make make a table like `user_transaction`, which has all of the >> relevant information for the transa

Re: [sqlalchemy] sqlalchemy get table with a string

2021-03-17 Thread Simon King
ble.insert().values(**tablo) db.session.execute(insert) Simon On Wed, Mar 17, 2021 at 4:19 PM FURKAN bilgin wrote: > > I updated sqlalchemy and now I get an error when accessing the database. And > their codes need to be coded: > What I really wanted to do was add data to

Re: [sqlalchemy] sqlalchemy get table with a string

2021-03-17 Thread Simon King
I assumed you were defining classes corresponding to your database tables, as shown here: https://docs.sqlalchemy.org/en/14/orm/tutorial.html#declare-a-mapping If that's not how you're using SQLAlchemy, you'll have to show your code. Simon On Wed, Mar 17, 2021 at 2:07 PM FURKAN bilgin wrote

Re: [sqlalchemy] sqlalchemy get table with a string

2021-03-17 Thread Simon King
classes[name] Another option could be to iterate over Base.__subclasses__: def get_table_by_name(name): for cls in Base.__subclasses__(): if cls.__name__ == name: return cls Hope that helps, Simon On Tue, Mar 16, 2021 at 7:14 PM FURKAN bilgin wrote

Re: [sqlalchemy] Injecting User info into _history table to track who performed the change

2021-03-15 Thread Simon King
/en/13/orm/session_api.html#sqlalchemy.orm.session.Session.info Then, in the before_flush event handler, I retrieve the request object from session.info, and then I can add whatever request-specific info I want to the DB. Simon On Sun, Mar 14, 2021 at 4:05 PM JPLaverdure wrote: > > Hi E

Re: [sqlalchemy] Create Sqlalchemy ORM class from regular class gets "has no attribute ''_sa_instance_state''"

2021-03-15 Thread Simon King
Student("Name3", "Sname3", clazz=clazz, code='cc7') ] You are creating an instance of "school.Class", which is the non-sqlalchemy base class. You probably meant to create an instance of "Class", which is the SQLAlchemy-mapped subclass, didn't

Re: [sqlalchemy] SQLAlchemy database record created on import of module

2021-03-15 Thread Simon King
e to print a stack trace) to find out where in your code you are adding this object to the session. Hope that helps, Simon On Fri, Mar 12, 2021 at 4:17 AM Advanced Spectrum wrote: > > I have a Base class like this: > > class FlagTable(Base): > > __tablename__ = "FLAG_TABL

Re: [sqlalchemy] Usage instructions for citext support not working

2021-02-15 Thread Simon King
To get zsh to not treat it as a pattern, enclose it in quotes: pip install 'sqlalcodegen[citext]' Hope that helps, Simon On Mon, Feb 15, 2021 at 12:38 PM Wilfried L. Bounsi wrote: > > Hello, > > I've been trying to enable citext support by following the installation &g

Re: [sqlalchemy] SQLAlchemy (v.1.3.22) can not find Teradata engine inside Amazon Glue Job's script in Amazon environment

2021-02-04 Thread Simon King
is not expecting to be loaded from a zip file at all, so you might have to find a different way of packaging it for the Amazon environment. As you suspected, it's not an SQLAlchemy question any more. Good luck! Simon On Thu, Feb 4, 2021 at 10:43 AM Anhelina Rudkovska wrote: > > Thanks

Re: [sqlalchemy] Creating column SQLAlchemy property on parent class based on child column property

2021-02-03 Thread Simon King
ment this as a hybrid property on Parent, where the "expression" part of the hybrid property constructs a subquery with a union or a join of all the child tables. It'll be pretty messy, and might not perform particularly well. Simon On Wed, Feb 3, 2021 at 10:08 AM Mehrdad Pedramfar wro

Re: [sqlalchemy] SQLAlchemy (v.1.3.22) can not find Teradata engine inside Amazon Glue Job's script in Amazon environment

2021-02-02 Thread Simon King
.dist-info" (or possible .egg-info) in your site-packages. The directory would contain an entry_points.txt file that points to the dialect class. Does your site-packages.zip contain that dist info directory with the entry_points file inside? Simon On Mon, Feb 1, 2021 at 4:50 PM Anhelina Rudkov

Re: [sqlalchemy] Behaviour when setting a foreign key column.

2020-12-14 Thread Simon King
the associated relationship to be updated immediately: https://docs.sqlalchemy.org/en/13/faq/sessions.html#i-set-the-foo-id-attribute-on-my-instance-to-7-but-the-foo-attribute-is-still-none-shouldn-t-it-have-loaded-foo-with-id-7 Hope that helps, Simon On Mon, Dec 14, 2020 at 12:50 PM João Miguel Neves

Re: [sqlalchemy] conditionals inside column_property

2020-12-11 Thread Simon King
priate SQL. The column_property mechanism accepts a ClauseElement and causes it to be added to the SQL when you later query the table. Simon On Fri, Dec 11, 2020 at 11:11 AM Jinghui Niu wrote: > > Thanks. One thing to clarify, I noticed that here you used `case` without > using in a

Re: [sqlalchemy] conditionals inside column_property

2020-12-11 Thread Simon King
aggr = column_property( case([(attr_a == 'go', attr_b + attr_c)], else_=attr_b - attr_c) ) Hope that helps, Simon On Fri, Dec 11, 2020 at 9:13 AM niuji...@gmail.com wrote: > > I have a mapped class: > > class Model(sqlalchemy.declarative_base()): > attr_a

Re: [sqlalchemy] Setting the FK not performed when relationship is declared

2020-12-10 Thread Simon King
I can't see anything obviously wrong with what you've written (you said "child.id is None", but I assume you meant child.parent_id). Can you provide a runnable example? Simon On Thu, Dec 10, 2020 at 8:27 AM Nikola Radovanovic wrote: > > Hi, > I have a FK in child pointing to

Re: [sqlalchemy] object “is already present in this session” when using a new session with older objects

2020-11-23 Thread Simon King
of typeDict, either by re-querying from the database, or by using session.merge with load=False. Hope that helps, Simon On Thu, Nov 19, 2020 at 11:16 PM Vinit Shah wrote: > > I posted this on StackOverflow a few days ago, but I haven't been able to > figure this one out yet. The orig

Re: [sqlalchemy] NEED HELP! Using Hybrid property in SQLAlchemy filter throws error

2020-10-22 Thread Simon King
goods_child_sizes table) Simon On Thu, Oct 22, 2020 at 2:41 PM Padam Sethia wrote: >> >> >> class FinishedGoodsChild(TimestampMixin, db.Model): >> >> id = db.Column(db.Integer, primary_key=True) >> >> hold_qty = db.Column(db.Float, default=0) >

Re: [sqlalchemy] NEED HELP! Using Hybrid property in SQLAlchemy filter throws error

2020-10-22 Thread Simon King
You don't need to add a parent_id column, you just need to write the full relationship condition inside that "select" statement. It would be much easier to explain if you can show your actual parent and child classes, including the relationship between them and the association tab

Re: [sqlalchemy] NEED HELP! Using Hybrid property in SQLAlchemy filter throws error

2020-10-21 Thread Simon King
.\ label('balance') You probably need something a bit more complicated than that - I didn't understand the join condition between parent and child in your example so I made up the "parent_id" column. Hope that helps, Simon On Tue, Oct 20, 2020 at 4:57 PM Padam

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 Simon King
Yep, I misunderstood what setinputsizes was doing. I thought it told pyodbc how it should handle a particular datatype, rather than telling it how to handle the set of parameters it is about receive in the next execute() call... Sorry for adding to the confusion, Simon On Fri, Oct 16, 2020 at 1

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 Simon King
e. If you can restrict yourself to SQL Server 2019, that might be a better option. Simon On Thu, Oct 15, 2020 at 10:08 AM Nicolas Lykke Iversen wrote: > > Thank you, Simon. > > I'm curious whether this is the way to do it in the future, or whether > SQLAlchemy should imple

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 Simon King
): cursor.setinputsizes([(pyodbc.SQL_WVARCHAR,0,0),]) https://docs.sqlalchemy.org/en/13/core/events.html#sqlalchemy.events.ConnectionEvents https://docs.sqlalchemy.org/en/13/core/events.html#sqlalchemy.events.ConnectionEvents.before_cursor_execute Hope that helps, Simon On Thu, Oct 15

Re: [sqlalchemy] extend automapped classes with a mixin

2020-10-12 Thread Simon King
eclarative_base: https://docs.sqlalchemy.org/en/13/orm/extensions/automap.html#sqlalchemy.ext.automap.automap_base ...and declarative_base accepts a "cls" argument which is used as the base class: https://docs.sqlalchemy.org/en/13/orm/extensions/declarative/api.html#sqlalche

Re: [sqlalchemy] ORM and objects with properties that need conversion to write to database

2020-10-08 Thread Simon King
tic-guid-type Hope that helps, Simon -- 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

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

2020-09-03 Thread Simon King
I can't see that changing. Simon On Thu, Sep 3, 2020 at 2:00 PM Nicolas Lykke Iversen wrote: > > Thanks Simon, > > Just to be clear: > >> dialect-specific options end up in table.dialect_options: >> https://docs.sqlalchemy.org/en/13/core/metadata.html#sqlalchemy.s

Re: [sqlalchemy] SQLAlchemy MYSQL query utf8 character problem

2020-09-03 Thread Simon King
ables have a default charset of latin1, and the others are utf8. The result is that the tables that are declared to hold latin1 data actually hold utf8, and the tables that are declared to hold utf8 actually hold double-encoded utf8. Simon -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mappe

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

2020-09-03 Thread Simon King
/dialects/mysql/base.py#L1871 whereas sqlite does this: https://github.com/sqlalchemy/sqlalchemy/blob/master/lib/sqlalchemy/dialects/sqlite/base.py#L1120 Simon On Thu, Sep 3, 2020 at 5:38 AM Nicolas Lykke Iversen wrote: > > Thank you, Simon. > > Yes, __table_args__ is the only reason

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

2020-09-01 Thread Simon King
t;sqlite_autoincrement": True, } id = sa.Column(sa.Integer(), primary_key=True) name = sa.Column(sa.Text()) engine = sa.create_engine("sqlite:///", echo=True) Base.metadata.create_all(engine) Simon On Fri, Aug 28, 2020 at 10:35 AM Nicolas Lykke Iversen wr

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

2020-08-20 Thread Simon King
n session.query(User): value = getattr(user, attrname) print(value) Simon On Wed, Aug 19, 2020 at 3:20 PM Mike Bayer wrote: > > __table__ is public (private would be a single or double underscore prefix > only), but also you could use inspect(cls).column_attrs: > > ht

Re: [sqlalchemy] Re: Deletion of a row from an association table

2020-08-15 Thread Simon King
data will not match what is in the database. Hope that helps, Simon On Wed, Aug 12, 2020 at 3:05 AM William Phillips wrote: > > For the sake of completeness I am including the code to disconnect an option > from a machine using only python/SQLite code. > > def removeOption(b

Re: [sqlalchemy] Flask SQlAlchemy BaseQuery Paginate not working correctly

2020-08-15 Thread Simon King
query.html#sqlalchemy.orm.query.Query.exists Hope that helps, Simon On Fri, Aug 14, 2020 at 3:56 PM Prerna Pandit wrote: > > Hey Simon, > > Thanks so much for replying to my question. I reworked my code to use > sqlalchemy ORM and took off flask and paginate so I can narrow down the >

Re: [sqlalchemy] Flask SQlAlchemy BaseQuery Paginate not working correctly

2020-08-14 Thread Simon King
along a one-to-many relationship, because if you have (for example) 2 "parent" objects, each with 5 "child" objects, the query will return 10 rows, but SQLAlchemy de-duplicates the results to return just the 2 parent objects. Simon On Thu, Aug 13, 2020 at 3:31 PM Prerna Pandit

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

2020-07-10 Thread Simon King
Not in the traditional sense, no. ORDER BY is implemented by the database, and with client-side encryption, the database only ever sees encrypted strings. Simon On Fri, Jul 10, 2020 at 8:41 AM Justin Van Vuuren wrote: > > Also, regarding the client side approach, would one be able

Re: [sqlalchemy] convert subset to dictionary

2020-07-08 Thread Simon King
hat the queries look correct (for example, they have the right join conditions). If they look OK but they run slowly, use your database's tools (eg. EXPLAIN or EXPLAIN ANALYZE) to understand why. Simon On Wed, Jul 8, 2020 at 8:22 AM Justvuur wrote: > > I'd like to redesign the DB b

Re: [sqlalchemy] convert subset to dictionary

2020-07-07 Thread Simon King
t swapping, which would hurt performance, in which case querying for smaller amounts of data might be better. Simon On Tue, Jul 7, 2020 at 12:53 PM Justvuur wrote: > > I'm currently testing with 7000 students with 181 subjects. > I first went over to the DB to run the query direc

Re: [sqlalchemy] convert subset to dictionary

2020-07-07 Thread Simon King
How long is it taking? You mentioned 2000 students with 100 subjects each, so there are something like 200,000 rows in the Subjects table, and you need to load all of it. I wouldn't expect that to take longer than a couple of seconds though. Simon On Mon, Jul 6, 2020 at 7:34 PM Justvuur wrote

Re: [sqlalchemy] convert subset to dictionary

2020-07-03 Thread Simon King
for every student in a single query: https://docs.sqlalchemy.org/en/13/orm/loading_relationships.html#joined-eager-loading Simon On Fri, Jul 3, 2020 at 1:36 PM Justvuur wrote: > > Hi Simon, thanks for the help! I've never used that before, it's quite handy. > > I'm looping through all the

Re: [sqlalchemy] convert subset to dictionary

2020-07-03 Thread Simon King
-examples.dynamic_dict https://docs.sqlalchemy.org/en/13/orm/examples.html#module-examples.vertical Hope that helps, Simon On Thu, Jul 2, 2020 at 8:46 PM Justvuur wrote: > > Hi there, > > I'm struggling to find an efficient way to get a two columned subset into > dictionary f

Re: [sqlalchemy] SQL injection

2020-07-02 Thread Simon King
ameterized and the parameters are sent separately, so attackers can't change the syntactic form of the statement. Simon On Wed, Jul 1, 2020 at 4:21 PM divyashi...@gmail.com wrote: > > SQL injections in the sense , malacious sql statements. or paylaod . > > On Wednesday, July 1, 2020 at 10:0

Re: [sqlalchemy] SQL injection

2020-07-01 Thread Simon King
Hi, What do you mean by "SQL injection"? Thanks, Simon On Tue, Jun 30, 2020 at 10:12 PM Divya Shivakumar wrote: > > Hey how do i generate new sql injections from sqlalchemy . Any links or > information is much appreciated > > -- > SQLAlchemy - > The Python SQ

Re: [sqlalchemy] Re: how can i remove an entry from relational database using sqlalchemy in python

2020-05-29 Thread Simon King
://docs.sqlalchemy.org/en/13/orm/basic_relationships.html#deleting-rows-from-the-many-to-many-table (note that accessing "contract.permissions" will load all the permissions for that contract from the database, which might be inefficient depending on your application) Hope that helps, Simon On F

Re: [sqlalchemy] Re: SQLAlchemy: UnicodeEncodeError: 'ascii' codec can't encode characters (db engine encoding ignored?)

2020-05-06 Thread Simon King
What are the values of "encoding" and "nencoding" on the connection object? https://github.com/oracle/python-cx_Oracle/issues/36 https://stackoverflow.com/a/37600367/395053 You probably need to grab the raw dbapi connection:

Re: [sqlalchemy] SQLAlchemy: UnicodeEncodeError: 'ascii' codec can't encode characters (db engine encoding ignored?)

2020-05-06 Thread Simon King
It might help to display the stack trace when the encoding fails, so we can see exactly where the error is coming from. Simon On Wed, May 6, 2020 at 9:01 AM Anno Nühm wrote: > > I am currently engaged in evaluating SQLAlchemy for a new project. When > trying to execute queries conta

Re: [sqlalchemy] looking for help building relationship that references an intermediate mixer table

2020-03-25 Thread Simon King
Do you need it to be an actual relationship? It's common to use an association proxy for this: https://docs.sqlalchemy.org/en/13/orm/extensions/associationproxy.html#simplifying-association-objects Hope that helps, Simon On Fri, Mar 20, 2020 at 7:47 PM Mark Aquino wrote: > > I'

Re: [sqlalchemy] Cleaning metadata

2020-03-25 Thread Simon King
It's difficult to answer this question without knowing how your code is structured. Are you reflecting your tables from the database, or have you defined them statically? What is the full stack trace when you get those errors? Simon On Wed, Mar 25, 2020 at 10:27 AM Javier Collado Jiménez wrote

Re: [sqlalchemy] SQLAlchemy URI (in superset) to connect to SSL enabled DRUI UI

2020-03-25 Thread Simon King
ts or you could use the "creator" argument to specify your own function for creating the connection: https://docs.sqlalchemy.org/en/13/core/engines.html#sqlalchemy.create_engine.params.creator Hope that helps, Simon On Wed, Mar 25, 2020 at 12:15 AM Lakshman Pervatoj wrote: > >

Re: [sqlalchemy] Bitwise AND operation in a select statement support in sqlalchemy

2020-02-25 Thread Simon King
n.ColumnElement.op Something like this: select([testa.c.id.op("&")(15)]) Hope that helps, Simon On Tue, Feb 25, 2020 at 5:02 PM Balukrishnan wrote: > > Table definition > > from sqlalchemy import * > testa = Table( > "testa", > metadata,

Re: [sqlalchemy] how to "explicitly" combine columns, for example get the child class value from a query on parent class from same named column?

2020-02-14 Thread Simon King
agining what it would mean to have an instance of B (which due to inheritance is also an instance of A) which has different values in A.visible_id and B.visible_id. Simon -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please prov

  1   2   3   4   5   6   7   8   9   10   >