I have written a couple queries in SQL, and I request assistance
in translating them into SQL Alchemy.



The first query concerns the mail filtering algorithm for a mail user
agent. I want to run something like this SQL.

    select mailfiling.manual_folder_id
    from mail
    natural join mailfiling
    join emailaddress on emailaddress.id = mail.sender_id
    where emailaddress.id in (7, 12)
    group by emailaddress.id, mailfiling.manual_folder_id
    order by count(*) desc limit 1;

Here are the relevant SQLAlchemy models.
https://thomaslevine.com/scm/pgmh/artifact/e278d413b3dd7661

I would probably use it as hybrid_property or a column_property
in the Mail class, returning the folder associated with a particular
mail.



The second query concerns the search index for the same mail user agent.
How do I assign the result of SQL functions? This SQL does what I want.

  create table test (t tsvector);
  insert into test (t) values (
    setweight(to_tsvector('english', 'Thomas Levine'), 'A') ||
    setweight(to_tsvector('english', 'blah blah'), 'B')
  );

I would use it in the initialization of the Mail model from the same
file as above.

-- 
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.

Reply via email to