Re: [sqlalchemy] PostgreSQL 9.1 on the horizon, cool new stuff
On Jan 30, 2014, at 9:52 PM, Lucas Taylor ltaylor.vo...@gmail.com wrote: Any notion of how one might instruct SQLAlchemy to (conditionally) create tables using UNLOGGED? I'd like to be able to modify the DDL for all CREATE TABLE statements under certain conditions (dialect=postgresql testing=True) If not under test, then there would be no need to modify CREATE TABLE. I'm thinking that it might involve some kind of before_create event and modifying the DDL, e.g. something that might start like: event.listen( metadata, 'before_create', DDL('CREATE UNLOGGED TABLE').execute_if(dialect='postgresql', callable_=isUnderTest, state=TESTING) Does this seem like the right direction? sorta, though you might also look into using @compiles on top of sqlalchemy.schema.CreateTable, see http://docs.sqlalchemy.org/en/rel_0_9/core/compiler.html. signature.asc Description: Message signed with OpenPGP using GPGMail
Re: [sqlalchemy] PostgreSQL 9.1 on the horizon, cool new stuff
On Friday, January 31, 2014 7:45:07 AM UTC-7, Michael Bayer wrote: On Jan 30, 2014, at 9:52 PM, Lucas Taylor ltaylo...@gmail.comjavascript: wrote: Any notion of how one might instruct SQLAlchemy to (conditionally) create tables using UNLOGGED? I'd like to be able to modify the DDL for all CREATE TABLE statements under certain conditions (dialect=postgresql testing=True) If not under test, then there would be no need to modify CREATE TABLE. I'm thinking that it might involve some kind of before_create event and modifying the DDL, e.g. something that might start like: event.listen( metadata, 'before_create', DDL('CREATE UNLOGGED TABLE').execute_if(dialect='postgresql', callable_=isUnderTest, state=TESTING) Does this seem like the right direction? sorta, though you might also look into using @compiles on top of sqlalchemy.schema.CreateTable, see http://docs.sqlalchemy.org/en/rel_0_9/core/compiler.html. Thanks! I took a stab at it using @compiles and came up with this: @compiles(CreateTable, 'postgresql') def compile_unlogged(create, compiler, **kwargs): if unittests and 'UNLOGGED' not in create.element._prefixes: create.element._prefixes.append('UNLOGGED') return compiler.visit_create_table(create) This subsection of the compiler docs was helpful: http://docs.sqlalchemy.org/en/rel_0_9/core/compiler.html#changing-the-default-compilation-of-existing-constructs -- 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 http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] PostgreSQL 9.1 on the horizon, cool new stuff
Thanks for the 'heads-up' Eric :-) ! Nothing to see here, move right along ! Except... Couple of interesting additions coming up in PostgreSQL 9.1 (still in beta) for anyone who's interested. Release notes: http://developer.postgresql.org/pgdocs/postgres/release-9-1.html A couple of selected items I found of interest: * New support for CREATE UNLOGGED TABLE -- a new type of table that is sort of in between temporary tables and ordinary tables. They are not crash-safe as they are not written to the write-ahead log and are not replicated if you have replication set up, but the tradeoff is they can be written to a lot faster. Could use these to speed up testing, or in other non-production scenarios where crashproofness is not a concern. * New support for Synchronous replication -- primary master waits for a standby to write the transaction information to disk before acknowledging the commit. This behavior can be enabled or disabled on a per-transaction basis. Also a number of new settings related to keeping a 'hot standby'. * They added a true serializable transaction isolation level. Previously, asking for serializable isolation guaranteed only that a single MVCC snapshot would be used for the entire transaction, which allowed certain documented anomalies. The old snapshot isolation behavior will now be accessible by using the repeatable read isolation level. --This one might be particularly interesting for SQLAlchemy-- * INSERT, UPDATE, and DELETE will now be allowed in WITH clauses; these commands can use RETURNING to pass data up to the containing query. While not strictly necesary, this can improve the clarity of SQL emitted by eliminating some nested sub-SELECTs. There is other cool stuff you can accomplish with this such as deleting rows from one table according to a WHERE clause inside of a WITH...RETURNING, and inserting the same rows into another table in the same statement. The recursive abilities of WITH statements can also be used now to perform useful maneuvers like recursive DELETEs in tree structures (as long as the data-modifying part is outside of the WITH clause). * New support for per-column collation settings (yawn... but someone somewhere needs this while migrating or something) * New support for foreign tables -- allowing data stored outside the database to be used like native postgreSQL-stored data (read-only). * Enum types can now be added to programmatically (i don't know if they can be removed from) via ALTER TYPE * Added CREATE TABLE IF NOT EXISTS syntax -- seems like SA's DDL machinery might want to use that in the checkfirst=True case to eliminate the separate check operation? A minor matter, but nice. * Added transaction-level advisory locks (non-enforced, application- defined) similar to existing session-level advisory locks. * Lots more (a dump + restore will be required between 9.0 and 9.1) -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.