I think you misunderstand `exists()` in SQLAlchemy and SQL. `exists()` is a convenience function to create a SQL `EXISTS` clause, which is an operator used for filtering subqueries.
The 'from_exists' is just a subquery. It is supposed to be used within a query which would then limit the query, not executed itself. See https://docs.sqlalchemy.org/en/14/core/selectable.html?#sqlalchemy.sql.expression.Exists https://docs.sqlalchemy.org/en/14/core/selectable.html?#sqlalchemy.sql.expression.exists https://docs.sqlalchemy.org/en/14/orm/query.html#sqlalchemy.orm.Query.exists https://www.w3schools.com/sql/sql_exists.asp On Tuesday, August 9, 2022 at 2:05:56 PM UTC-4 Justvuur wrote: > Hi there, > > When creating another column property in a model that makes use of the > exists(), I noticed that the exists does a "select *". > > *For example, the form exists below:* > class Contact(ResourceMixin, db.Model): > __tablename__ = 'contacts' > > form_contacts = db.relationship(FormContact, backref='contact', > passive_deletes=True) > > form_exists = column_property( > exists().where(and_( FormContact .form_contact_id == id, > FormContact.partnership_id == partnership_id > )).label('form_contact_exist'), deferred=True > ) > *prints out to be something like:* > exists(select * from form_contacts where form_contacts.form_contact_id == > id and form_contacts. partnership_id == partnership_id) > > Does the exists "stop" the query once one row is returned or does it > execute the entire select all query? > If the latter, is there a way to limit the select all to one row? > > Regards, > Justin > -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/0cb5d3e1-8e8d-4367-861d-f5e8328c4ffen%40googlegroups.com.