On Wed, Mar 18, 2020, at 1:23 PM, Soumaya Mauthoor wrote: > Hello > > I have two uses cases: > > (1) drop cascade as option > I know I can use custom compilation to add cascade for postgres databases > using this example: > https://stackoverflow.com/questions/38678336/sqlalchemy-how-to-implement-drop-table-cascade > Is it possible to use custom compilation to add cascade as an optional > keyword argument to drop()?
drop() doesn't accept any optional keyword arguments so you're best off making your own subclass of DropTable called DropTableCascade and just executing it: conn.execute(DropTableCascade(mytable)) > > (2) overwriting func functions > Is it possible to overwrite func.greatest to return func.max for SQLite? generic functions are used for this. Since "max" is a multiple-typed function you can use a helper class called ReturnTypeFromArgs: from sqlalchemy.sql.functions import ReturnTypeFromArgs from sqlalchemy.ext.compiler import compiles from sqlalchemy.sql import literal_column from sqlalchemy.sql import func from sqlalchemy.dialects import sqlite class greatest(ReturnTypeFromArgs): pass @compiles(greatest, "sqlite") def _render_max(elem, compiler, **kw): return "max(%s)" % compiler.process(elem.clauses) print(func.greatest(literal_column("foo"))) print(func.greatest(literal_column("foo")).compile(dialect=sqlite.dialect())) > > I'm trying to learn more about custom compilation in general. This page is > very helpful: > http://docs.sqlalchemy.org/en/latest/core/compiler.html > > Are there other resources you recommend? > > Soumaya > > > -- > 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/CAN14jWQGC%2BzfNAEfFCiRHmTbCsXq2NrWGPoE0qpNhcTWx55-iw%40mail.gmail.com > > <https://groups.google.com/d/msgid/sqlalchemy/CAN14jWQGC%2BzfNAEfFCiRHmTbCsXq2NrWGPoE0qpNhcTWx55-iw%40mail.gmail.com?utm_medium=email&utm_source=footer>. -- 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/be8be4ca-7393-48de-bbb8-32b649bd7a13%40www.fastmail.com.