Re: [sqlalchemy] emulating psql's "\copy" function?

2015-10-13 Thread Jon Nelson
On Tue, Oct 13, 2015 at 2:49 PM, Jon Nelson <jnel...@jamponi.net> wrote: > On Tue, Oct 13, 2015 at 1:55 PM, Jonathan Vanasco <jonat...@findmeon.com> > wrote: >> As part of an archiving routine that uses SqlAlchemy, I need to execute some >> pretty specific com

Re: [sqlalchemy] emulating psql's "\copy" function?

2015-10-13 Thread Jon Nelson
On Tue, Oct 13, 2015 at 1:55 PM, Jonathan Vanasco wrote: > As part of an archiving routine that uses SqlAlchemy, I need to execute some > pretty specific commands using `\copy` to archive a selection of columns, in > a special order, into a csv. > > Doing some digging,

[sqlalchemy] Difficulty pre-populating session without using .get

2015-01-09 Thread Jon Nelson
I'm having a bit of trouble. Let's say I have N primary key IDs for a set of objects. I want to load all of those objects into the session, but I'd like that to happen all in one query. dbsess.query(object_type).filter(object_type.primary_key.in_(some_list_of_ids)).all() # then I made (one or

Re: [sqlalchemy] Difficulty pre-populating session without using .get

2015-01-09 Thread Jon Nelson
On Fri, Jan 9, 2015 at 1:19 PM, Michael Bayer mike...@zzzcomputing.com wrote: Jon Nelson jnel...@jamponi.net wrote: I'm having a bit of trouble. Let's say I have N primary key IDs for a set of objects. I want to load all of those objects into the session, but I'd like that to happen all

Re: [sqlalchemy] Difficulty pre-populating session without using .get

2015-01-09 Thread Jon Nelson
On Fri, Jan 9, 2015 at 2:21 PM, Michael Bayer mike...@zzzcomputing.com wrote: Jon Nelson jnel...@jamponi.net wrote: so you could use either merge() or merge_result() but to avoid any SQL set load=False. When I tried with load=False, I got an error. I am using 0.9.8. care to be more

Re: [sqlalchemy] Difficulty pre-populating session without using .get

2015-01-09 Thread Jon Nelson
On Fri, Jan 9, 2015 at 2:42 PM, Jon Nelson jnel...@jamponi.net wrote: On Fri, Jan 9, 2015 at 2:21 PM, Michael Bayer mike...@zzzcomputing.com wrote: Jon Nelson jnel...@jamponi.net wrote: so you could use either merge() or merge_result() but to avoid any SQL set load=False. When I tried

[sqlalchemy] mysql vs. postgresql introspection and unique indices

2014-11-14 Thread Jon Nelson
While using 'Inspector' to introspect MySQL and PostgreSQL databases dialects, I've noticed some slight variation: For MySQL, a UNIQUE table constraint also shows up as an Index (with unique=True). Ditto PostgreSQL (as of 0.9.8). Looking at the current HEAD, it appears that PostgreSQL has some

[sqlalchemy] a problem recently encountered with the example 'Explain'

2014-11-10 Thread Jon Nelson
Using this https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/Explain if I take a select statement, and then produce an insert statement using i = some_table.insert(inline=True).from_select( some_select ) and then: e = Explain(i) I can't execute(e) because the statement is rendered

Re: [sqlalchemy] a problem recently encountered with the example 'Explain'

2014-11-10 Thread Jon Nelson
Now the statement doesn't render with RETURNING, however I still get this: AttributeError: 'Explain' object has no attribute '_returning' -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from

[sqlalchemy] Not identifying all unique constraints in sqlite

2014-10-28 Thread Jon Nelson
In sqlite you can define a unique constraint without a name (and without CONSTRAINT): CREATE TABLE foo (a int, b int, UNIQUE (a,b)); The SQLAlchemy get_unique_constraints doesn't pick that up, due to the regex looking for CONSTRAINT some name UNIQUE (columns here). What's a reasonable

[sqlalchemy] table.update() and CTE

2014-07-25 Thread Jon Nelson
I seem to be having some trouble generating an update statement like this: with baz AS ( select name, coalesce( exists ( select 1 from bar where bar.name=foo.name ), False) AS found_name from foo ), update FOO SET found_name = baz.found_name FROM

[sqlalchemy] history and postgresql arrays

2014-05-27 Thread Jon Nelson
I noticed something kinda weird the other day. Let's say I have an object 'o' with two fields: num (an integer) and nums (an array of integers). Using 'inspect' and some trickery: d = dict(sa.inspect(o).attrs) d['num'].history History(added=(), unchanged=(10), deleted=()) d['nums'].history

[sqlalchemy] logging question

2013-11-19 Thread Jon Nelson
Greetings, once more! I'm having some trouble with logging. Before I call any sqlalchemy functions or bits (but after sqlalchemy is imported), I use logging.config.fileConfig(...) to configure the logging. The file is set to configure sqlalchemy at NOTSET and sqlalchemy.engine and

Re: [sqlalchemy] logging question

2013-11-19 Thread Jon Nelson
On Tue, Nov 19, 2013 at 12:17 PM, Michael Bayer mike...@zzzcomputing.com wrote: SQLAlchemy will affect the config of logging only if any of the “echo” flags are used - the effect of echo=True is that it calls logging.basicConfig(). This config will occur in addition to the config that you

Re: [sqlalchemy] Using PostgreSQL DELETE ... USING tableA... syntax

2013-11-16 Thread Jon Nelson
That's pretty spectacular! Will something like that make it into a future release of SQLAlchemy? -- Jon -- 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] declarative, reflection, and secondary tables.

2013-11-16 Thread Jon Nelson
I've been experiencing a weirdness. Using SQLAlchemy 0.8.3 and PostgreSQL with declarative (and deferred reflection), if I don't manually force a reflection *before* I call prepare then - when I use certain objects - I get an error which indicates that SQLAlchemy did not reflect secondary tables.

[sqlalchemy] Using PostgreSQL DELETE ... USING tableA... syntax

2013-11-15 Thread Jon Nelson
How might one extend a Delete clause such that I can use USING in the statement? Something like this (given t2 is a Table (or selectable?)): Turn this (assuming SomeObject is tied to t1): q = sess.query(SomeObject) q = q.filter(...) q = q.filter(SomeObject.some_column==t2.c.some_other_column)

[sqlalchemy] changing the column order of a select

2013-07-24 Thread Jon Nelson
Let's say I've built up a select statement but only after it's built do I know the order of the columns that I'd ultimately prefer. What's the best way to change the column order of a select? -- Jon Software Blacksmith -- You received this message because you are subscribed to the Google

[sqlalchemy] trouble with postgresql ANY

2013-05-28 Thread Jon Nelson
I'm having difficulty using PostgreSQL's ANY operator (for use with arrays). I've tried several variations of the syntax provided in the documentation, but all I ever get is: AttributeError: 'SQLCompiler' object has no attribute 'visit_any' What am I likely doing wrong? I've tried (using

Re: [sqlalchemy] performance vs. psycopg2

2011-12-16 Thread Jon Nelson
On Fri, Dec 16, 2011 at 3:30 AM, Gaëtan de Menten gdemen...@gmail.com wrote: On Thu, Dec 15, 2011 at 19:52, Jon Nelson jnel...@jamponi.net wrote: On Thu, Dec 15, 2011 at 12:01 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Dec 15, 2011, at 12:51 PM, Jon Nelson wrote: Up front, I'm

Re: [sqlalchemy] SQLA without the ORM?

2011-12-16 Thread Jon Nelson
On Fri, Dec 16, 2011 at 2:55 PM, Vlad K. v...@haronmedia.com wrote: Hi all! I have a few scenarios here that I believe are best solved without the ORM overhead. For example, various log tables that do not require a primary key, the rows are practically immutable, but are queried back for

[sqlalchemy] performance vs. psycopg2

2011-12-15 Thread Jon Nelson
Up front, I'm not using the ORM at all, and I'm using SQLAlchemy 0.7.4 with psycopg2 2.4.3 on PostgreSQL 8.4.10 on Linux x86_64. I did some performance testing. Selecting 75 million rows (a straight up SELECT colA from tableA) from a 5GB table yielded some interesting results. psycopg2 averaged

Re: [sqlalchemy] performance vs. psycopg2

2011-12-15 Thread Jon Nelson
On Thu, Dec 15, 2011 at 12:01 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Dec 15, 2011, at 12:51 PM, Jon Nelson wrote: Up front, I'm not using the ORM at all, and I'm using SQLAlchemy 0.7.4 with psycopg2 2.4.3 on PostgreSQL 8.4.10 on Linux x86_64. I did some performance testing

[sqlalchemy] IS DISTINCT FROM

2011-10-14 Thread Jon Nelson
What is the SA equivalent of: UPDATE foo SET bar=some_function(baz) WHERE bar IS DISTINCT FROM some_function(baz) I get this far (assuming 't' is a Table instance): t.update().values(t.c.bar=sa.func.some_function(t.c.baz).where( ... what do I put here ) IS DISTINCT FROM (and IS NOT

[sqlalchemy] Re: IS DISTINCT FROM

2011-10-14 Thread Jon Nelson
On Fri, Oct 14, 2011 at 4:45 PM, Jon Nelson jnel...@jamponi.net wrote: What is the SA equivalent of: UPDATE foo SET bar=some_function(baz) WHERE bar IS DISTINCT FROM some_function(baz) I get this far (assuming 't' is a Table instance): t.update().values(t.c.bar=sa.func.some_function

Re: [sqlalchemy] Re: IS DISTINCT FROM

2011-10-14 Thread Jon Nelson
On Fri, Oct 14, 2011 at 8:12 PM, Michael Bayer mike...@zzzcomputing.com wrote: for now yes, I've not heard of IS DISTINCT FROM before. In the right places, it's mighty useful. -- Jon -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to

Re: [sqlalchemy] Re: Postgresql and reflection: system tables VS information_schema

2011-10-05 Thread Jon Nelson
On Wed, Oct 5, 2011 at 10:56 AM, Michael Bayer mike...@zzzcomputing.com wrote: that bug is fixed, you can get the tip at http://hg.sqlalchemy.org/sqlalchemy/archive/default.tar.gz . Cool. Regarding the issues surrounding postgresql introspection and the information_schema -- perhaps if patches

[sqlalchemy] problem with with_only_columns

2011-07-01 Thread Jon Nelson
I'm using sqlalchemy 0.7.1 on openSUSE 11.4 (which has python2.7) but the problem was also observed with older versions of python. Basically, with_only_columns seems to lose information about the columns: import sqlalchemy as sa e = sa.create_engine( 'sqlite:///' ) conn = e.connect() m =

[sqlalchemy] begin_nested failures starting with 0.7

2011-06-01 Thread Jon Nelson
I've got a chunk of code that started failed as soon as I started testing with 0.7. The failure is: sqlalchemy.exc.StatementError: This Connection is closed '\nCREATE TABLE bar (\n\ta TEXT NOT NULL\n)\n\n' None I'll note that the logging indicates that the connection was returned to the pool

Re: [sqlalchemy] begin_nested failures starting with 0.7

2011-06-01 Thread Jon Nelson
On Wed, Jun 1, 2011 at 4:47 PM, Michael Bayer mike...@zzzcomputing.com wrote: metadata.reflect() would close() the connection used for reflection as it assumed it was passed an Engine, not a Connection, fixed in r926ee70b67ff.   Nothing to do with begin_nested() or anything like that. Why

Re: [sqlalchemy] begin_nested failures starting with 0.7

2011-06-01 Thread Jon Nelson
On Wed, Jun 1, 2011 at 6:00 PM, Jon Nelson jnel...@jamponi.net wrote: On Wed, Jun 1, 2011 at 4:47 PM, Michael Bayer mike...@zzzcomputing.com wrote: metadata.reflect() would close() the connection used for reflection as it assumed it was passed an Engine, not a Connection, fixed

[sqlalchemy] Fwd: [BUGS] database introspection error

2011-04-21 Thread Jon Nelson
introspection error To: Jon Nelson jnelson+pg...@jamponi.net Cc: pgsql-b...@postgresql.org Jon Nelson jnelson+pg...@jamponi.net writes: SQLAlchemy encountered an error introspecting the tables. After inspecting the SQL that it was running, I boiled it down to this: SELECT c.relname,  a.attname

[sqlalchemy] bug: distinct ON using subquery with un-named alias fails.

2011-04-21 Thread Jon Nelson
I have a test case. If this formats badly, I'll attach it as a file. I'm not sure if this is a distinct on problem or not (probably not, but here is a test case anyway). If I don't specify a name for the alias, the compile fails. :-( diff -r 070e47edcfad test/dialect/test_postgresql.py ---

[sqlalchemy] LIKE operator and double percent signs

2011-02-25 Thread Jon Nelson
I've been wondering something about sqlalchemy - let's say I have a text column foo. Being able to do foo.startswith(some_value), foo.endswith, foo.like and so on is really nice. However, I've noticed that the SQL that is emitted contains two percent signs. However, I thought only one was

Re: [sqlalchemy] LIKE operator and double percent signs

2011-02-25 Thread Jon Nelson
as atoms (individual arguments rather than a single, concatenated string) then '%%' is unnecessary. On Feb 25, 2011, at 8:53 AM, Jon Nelson wrote: I've been wondering something about sqlalchemy - let's say I have a text column foo. Being able to do foo.startswith(some_value), foo.endswith

[sqlalchemy] documentation weirdness

2011-02-24 Thread Jon Nelson
Looking at the docs for http://www.sqlalchemy.org/docs/core/expression_api.html#sqlalchemy.sql.expression.Select.locate_all_froms the documentation renders 'locate_all_froms(self)' as though it were not a callable but an attribute. What's up with that? -- Jon -- You received this message

Re: [sqlalchemy] execute at beginning of every session

2011-02-16 Thread Jon Nelson
On Wed, Feb 16, 2011 at 9:22 AM, Landreville ja...@deadtreepages.com wrote: Hi, I am trying to set a session variable (call a function with a value) in postgres at the beginning of every session that SQLAlchemy starts. I'm using the session variable to specify the currently logged in user for

Re: [sqlalchemy] execute at beginning of every session

2011-02-16 Thread Jon Nelson
On Wed, Feb 16, 2011 at 10:51 AM, Michael Bayer mike...@zzzcomputing.com wrote: On Feb 16, 2011, at 10:22 AM, Landreville wrote: Hi, I am trying to set a session variable (call a function with a value) in postgres at the beginning of every session that SQLAlchemy starts. I'm using the

Re: [sqlalchemy] execute at beginning of every session

2011-02-16 Thread Jon Nelson
On Wed, Feb 16, 2011 at 12:15 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Feb 16, 2011, at 12:54 PM, Jon Nelson wrote: On Wed, Feb 16, 2011 at 10:51 AM, Michael Bayer mike...@zzzcomputing.com wrote: On Feb 16, 2011, at 10:22 AM, Landreville wrote: Hi, I am trying to set

Re: [sqlalchemy] SQLAlchemy 0.7 beta 1 released

2011-02-13 Thread Jon Nelson
On Sat, Feb 12, 2011 at 8:11 PM, Michael Bayer mike...@zzzcomputing.comwrote: On Feb 12, 2011, at 8:29 PM, Jon Nelson wrote: On Sat, Feb 12, 2011 at 6:51 PM, Michael Bayer mike...@zzzcomputing.comwrote: Hey list - The first beta release of SQLAlchemy 0.7 is available for download

Re: [sqlalchemy] SQLAlchemy 0.7 beta 1 released

2011-02-12 Thread Jon Nelson
On Sat, Feb 12, 2011 at 6:51 PM, Michael Bayer mike...@zzzcomputing.comwrote: Hey list - The first beta release of SQLAlchemy 0.7 is available for download. Awesome! I just gave it a test and, except for being bit by the removal of the _CursorFairy, it appears to work very well! I didn't do

[sqlalchemy] Sessions and Transactions - What am I doing wrong?

2011-02-06 Thread Jon Nelson
The following python program fails at the sess.begin() line when executed with autocommit set to False. Specifically, when invoked with a database URI and an argument of 'no' (or anything except 'yes' or 'true') the following exception is raised: sqlalchemy.exc.InvalidRequestError: A transaction

[sqlalchemy] logging bug in 0.6.6?

2011-01-27 Thread Jon Nelson
I'm trying to diagnose an issue with temporary tables, so I cranked up the debug levels to DEBUG. I noticed something strange: 2011-01-27 09:34:12,818 DEBUG [sqlalchemy.pool.QueuePool.0x...e410] Connection connection object at 0x12e1d50; dsn: 'dbname=BLAH host=localhost user=BLAH

Re: [sqlalchemy] can't build c extensions for 0.6.6 on CentOS 5.5

2011-01-13 Thread Jon Nelson
On Thu, Jan 13, 2011 at 9:12 AM, Michael Bayer mike...@zzzcomputing.com wrote: assuming this is also your ticket #2023 ? http://www.sqlalchemy.org/trac/ticket/2023 That is not my ticket, but surely appears to be related! -- Jon -- You received this message because you are subscribed to

[sqlalchemy] can't build c extensions for 0.6.6 on CentOS 5.5

2011-01-12 Thread Jon Nelson
I'm unable to build the C extensions for SQLAlchemy 0.6.6 on CentOS 5.5: gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fPIC -I/usr/include/python2.4 -c

[sqlalchemy] MetaData, postgresql, and temporary tables

2010-11-22 Thread Jon Nelson
I have an app where I think I'm going to want to use a TEMPORARY TABLE like this: CREATE TEMPORARY TABLE results AS SELECT .; and then do two things: 1. I need a select count(1) from that table 2. I need to be able to iterate over the rows in that table The reason I am using a TEMPORARY

Re: [sqlalchemy] Re: Postgresql Partition / INHERIT and table names....

2010-09-13 Thread Jon Nelson
On Mon, Sep 13, 2010 at 3:39 PM, Gregg Lind gregg.l...@gmail.com wrote: So, there is a slight wart here: q = select(Partition(t1,'myt1')) q.append_column(Partition(t1,'myt1').c.data) will give: from myt1,myt1 I think this is an artifact of the   'alias' heritage.  Ideas? Don't

Re: [sqlalchemy] isolation_level and psycopg2?

2010-08-10 Thread Jon Nelson
Confirmed - your patch works great: [pid 12905] sendto(3, Q\0\0\0008BEGIN; SET TRANSACTION ISOLATION LEVEL SERIALIZABLE\0, 57, 0, NULL, 0) = 57 -- Jon -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to

[sqlalchemy] isolation_level and psycopg2?

2010-08-09 Thread Jon Nelson
I tried setting isolation_level to SERIALIZABLE in my create_engine options, while using psycopg2. However, an strace clearly shows that it is using READ COMMITTED. Is setting the isolation_level not supported with psycopg2? -- See, when the GOVERNMENT spends money, it creates jobs; whereas

Re: [sqlalchemy] isolation_level and psycopg2?

2010-08-09 Thread Jon Nelson
On Mon, Aug 9, 2010 at 11:27 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Aug 10, 2010, at 12:03 AM, Jon Nelson wrote: I tried setting isolation_level to SERIALIZABLE in my create_engine options, while using psycopg2. However, an strace clearly shows that it is using READ COMMITTED

[sqlalchemy] strange error with dynamic_loader

2010-08-04 Thread Jon Nelson
It seems as though attributes which are dynamic_loaders cannot be told to eagerly load subattributes which are themselves dynamic_loaders. IE, A has dynamic_loader for instances of B, which has dynamic_loader for instances of C. Assuming we have an instance of A, this works fine: query =

[sqlalchemy] how to translate this sql

2010-07-27 Thread Jon Nelson
I have two questions: 1. I'm using postgresql, and I sometimes need to do column type conversions. In postgresql, this is normally done with the ::FOO operator where FOO is a data *type*. Somtimes, but not usually, these data types are also available in function-like factories, but in this case

Re: [sqlalchemy] how to translate this sql

2010-07-27 Thread Jon Nelson
On Tue, Jul 27, 2010 at 11:08 AM, Michael Bayer mike...@zzzcomputing.com wrote: On Jul 27, 2010, at 11:49 AM, Jon Nelson wrote: I have two questions: 1. I'm using postgresql, and I sometimes need to do column type conversions. In postgresql, this is normally done with the ::FOO operator

Re: [sqlalchemy] how to translate this sql

2010-07-27 Thread Jon Nelson
On Tue, Jul 27, 2010 at 11:35 AM, Jon Nelson jnel...@jamponi.net wrote: On Tue, Jul 27, 2010 at 11:08 AM, Michael Bayer mike...@zzzcomputing.com wrote: On Jul 27, 2010, at 11:49 AM, Jon Nelson wrote: I have two questions: 1. I'm using postgresql, and I sometimes need to do column type

Re: [sqlalchemy] problem with select([table.c.column1, table.c.column1])

2010-06-22 Thread Jon Nelson
On Tue, Jun 22, 2010 at 8:55 AM, Michael Bayer mike...@zzzcomputing.com wrote: On Jun 21, 2010, at 7:52 PM, Jon Nelson wrote: On Mon, Jun 21, 2010 at 5:55 PM, Michael Bayer mike...@zzzcomputing.com wrote: not a bug, that's the correct behavior. Can you explain how it is correct? I asked

[sqlalchemy] problem with select([table.c.column1, table.c.column1])

2010-06-21 Thread Jon Nelson
I'm encountering a problem with SA 0.6.1 I have a select statement which selects the same column twice (and some other stuff, too). However, when the query is run (or printed), the column only shows up once. This seems like a bug. Example: from sqlalchemy import create_engine, select, Table,

Re: [sqlalchemy] problem with select([table.c.column1, table.c.column1])

2010-06-21 Thread Jon Nelson
it for what ultimately becomes an insert into () select (this, that, theother, col1, col1) On Jun 21, 2010, at 5:35 PM, Jon Nelson wrote: I'm encountering a problem with SA 0.6.1 I have a select statement which selects the same column twice (and some other stuff, too). However, when the query

[sqlalchemy] Window function support?

2010-05-24 Thread Jon Nelson
I have a query which requires the use of windowing functions in postgresql. Specifically, I require select distinct S.c1, first_value(c2) over (partition by S.c1 order by c2 desc) c3 from How might I accomplish this? Will there be windowing function support in an upcoming release of SA? --

[sqlalchemy] constant tables / VALUES expression

2010-05-17 Thread Jon Nelson
How do I translate the following: select A.column, V.queried from A, (VALUES ( ('foo'), ('bar') )) as V (queried) where A.column2 = V.queried; into sqlalchemy-speak. I'm not using the ORM. http://www.postgresql.org/docs/8.4/static/sql-values.html -- Jon -- You received this message because

Re: [sqlalchemy] constant tables / VALUES expression

2010-05-17 Thread Jon Nelson
On Mon, May 17, 2010 at 8:58 AM, Michael Bayer mike...@zzzcomputing.com wrote: it is here: http://groups.google.com/group/sqlalchemy/browse_thread/thread/7f950b628d7ebee5/4421b272d4c7f91f let me add that to the wiki Cool! However, http://www.postgresql.org/docs/8.4/static/sql-values.html

Re: [sqlalchemy] constant tables / VALUES expression

2010-05-17 Thread Jon Nelson
On Mon, May 17, 2010 at 8:58 AM, Michael Bayer mike...@zzzcomputing.com wrote: it is here: http://groups.google.com/group/sqlalchemy/browse_thread/thread/7f950b628d7ebee5/4421b272d4c7f91f let me add that to the wiki The part about the thread that worries me a bit is this: (%s) % ,

Re: [sqlalchemy] constant tables / VALUES expression

2010-05-17 Thread Jon Nelson
On Mon, May 17, 2010 at 9:32 AM, Michael Bayer mike...@zzzcomputing.com wrote: On May 17, 2010, at 10:14 AM, Jon Nelson wrote: On Mon, May 17, 2010 at 8:58 AM, Michael Bayer mike...@zzzcomputing.com wrote: it is here: http://groups.google.com/group/sqlalchemy/browse_thread/thread

[sqlalchemy] insert() and sa.func.something

2010-05-03 Thread Jon Nelson
I have a custom sql function in postgresql that needs to be applied to some data that I would like to insert. The SQL for this might look like: INSERT INTO table (col1, col2, col3) VALUES ('foo', 3, custom_function('cheese')); How do I do this with sqlalchemy's lower-level table.insert()

[sqlalchemy] best-practices question

2010-03-30 Thread Jon Nelson
Let's say I have a database with hundreds or even thousands of tables. The table structure for this set of tables is *exactly* the same. Furthermore, let's say the name of each table is predictable. For example, something like: tablename_2010_03_05 What I'd like to know is how to best manage

[sqlalchemy] Re: executemany + postgresql

2009-11-07 Thread Jon Nelson
On Fri, Nov 6, 2009 at 9:57 AM, Michael Bayer mike...@zzzcomputing.com wrote: Before I even posted I resorted to strace. strace immediately confirmed my suspicion - when using psycopg2 I don't see one big fat INSERT with lots of binds, I see one INSERT per bind, and it's this that is

[sqlalchemy] Re: executemany + postgresql

2009-11-07 Thread Jon Nelson
On Sat, Nov 7, 2009 at 11:58 AM, Michael Bayer mike...@zzzcomputing.com wrote: On Nov 7, 2009, at 12:53 PM, Jon Nelson wrote: have you asked about this on the psycopg2 mailing list ?   its at http://mail.python.org/mailman/listinfo/python-list  .   Let me know if you do, because I'll get

[sqlalchemy] Re: executemany + postgresql

2009-11-07 Thread Jon Nelson
On Sat, Nov 7, 2009 at 3:02 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Nov 7, 2009, at 1:30 PM, Jon Nelson wrote:  File pg8000/protocol.py, line 121, in serialize    val = struct.pack(!i, len(val) + 4) + val UnicodeDecodeError: 'ascii' codec can't decode byte 0x8d in position 3

[sqlalchemy] reflected tables and defaults

2009-09-28 Thread Jon Nelson
Is there a way to add a default to a column for a table that is autoreflected? I'm not even sure that's what I want to do, because what I *want* to do is this: Whenever an instance of Car is pulled from the database, I would like to make sure that it has an Engine associated with it, even if no

[sqlalchemy] Bug in ORM: SA 0.5.5.

2009-08-17 Thread Jon Nelson
I'm pretty sure I've hit some sort of weird bug in SA's ORM module. I have a database which is autoreflected (sorry), and one of the tables is self-referential via foreign-key. Additionally, there is a database default and a NOT NULL constraint. This relationship is described as a relation named

[sqlalchemy] logging after engine creation

2009-07-29 Thread Jon Nelson
I was recently trying to change the logging from the default to INFO for sqlalchemy.engine. This works great - so long as I do it at startup, before I make any connections, etc, however once I've created my engine instance I don't seem to be able to change the logging level, at least not in the

[sqlalchemy] README.unittests: missing command to setup.py

2009-07-29 Thread Jon Nelson
I followed the instructions and they didn't work: The file README.unittests states: $ export PYTHONPATH=. $ python setup.py -d . but this is what I get: usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: setup.py --help [cmd1 cmd2 ...] or: setup.py

[sqlalchemy] Re: strange problem with relation(..)

2009-07-29 Thread Jon Nelson
On Wed, Jul 29, 2009 at 9:16 PM, Michael Bayermike...@zzzcomputing.com wrote: On Jul 29, 2009, at 10:10 PM, BigJon wrote: On Jul 21, 2:53 pm, Michael Bayer mike...@zzzcomputing.com wrote: Jon Nelson wrote: The parent_id is NOT NULL and has no default. Doing something like this doesn't

[sqlalchemy] Re: strange problem with relation(..)

2009-07-29 Thread Jon Nelson
On Wed, Jul 29, 2009 at 9:54 PM, Michael Bayermike...@zzzcomputing.com wrote: On Jul 29, 2009, at 10:48 PM, Jon Nelson wrote: sure just use default=my_callable(ctx).  the ctx contains the bind parameters for the current row.   you could also just use a MapperExtension. I am not sure how

[sqlalchemy] Re: strange problem with relation(..)

2009-07-21 Thread Jon Nelson
On Tue, Jul 21, 2009 at 1:10 PM, Jon Nelsonjnel...@jamponi.net wrote: On Tue, Jul 21, 2009 at 10:47 AM, Michael Bayermike...@zzzcomputing.com wrote: Jon Nelson wrote: I encountered an odd issue today that I can't explain, and it seems like a bug. I've checked 0.5.4p2 and 0.5.5

[sqlalchemy] strange problem with relation(..)

2009-07-20 Thread Jon Nelson
I encountered an odd issue today that I can't explain, and it seems like a bug. I've checked 0.5.4p2 and 0.5.5, and the behavior is the same. I wrote a test (add to test/orm/test_relationships.py) to demonstrate it, which is below. If I change the test from: for child in root.children:

[sqlalchemy] implicit vs explicit join

2009-01-27 Thread Jon Nelson
I have a question about implicit vs explicit joins in SA. I have three tables with an odd relationship (legacy DB issues). Assume tables 'accounts' and 'account_config' and a secondary table 'account_to_config'. The true nature of the relation is 1:1, however (again, it's an inherited schema...)

[sqlalchemy] Re: Best way to count( some_relation )

2009-01-27 Thread Jon Nelson
im committing something that will make that exact phrase work (its in rev 5734). using a released version of SQLA, for now say id.in_(query.statement). I took at look at those changes and they look awesome! If I understand the changes correctly, however, then I wonder what purpose

[sqlalchemy] and_ and or_ precedence

2009-01-27 Thread Jon Nelson
I recently ran into an issue. Is it a bug? No. However, it made my brain hurt for a little bit until I remembered the SQL precedence rules for AND and OR. The operator precedence of AND and OR is known (AND takes precedence). However, it can make humans hurt their brains a bit to see SQL without

[sqlalchemy] Re: Best way to count( some_relation )

2009-01-26 Thread Jon Nelson
If I try that, I get: sqlalchemy.exc.ProgrammingError: (ProgrammingError) aggregates not allowed in WHERE clause The SQL generated is: SELECT account.accountid AS account_accountid FROM account JOIN userinfo ON account.accountid = userinfo.accountid WHERE count(userinfo.userid) %(count_1)s

[sqlalchemy] Re: Best way to count( some_relation )

2009-01-26 Thread Jon Nelson
On Mon, Jan 26, 2009 at 5:21 PM, Jon Nelson jnel...@jamponi.net wrote: ... If I start with this subquery: q0 = s.query(Account.accountid, sa.func.count(User.userid).label('user_count')) .join(Account.users) .group_by(Account.accountid) .having(sa.func.count(User.userid)1

[sqlalchemy] Re: Best way to count( some_relation )

2009-01-26 Thread Jon Nelson
I assumed it was a bug due to the presence of a python-style string substitution. ... another option is sess.query(Account).filter(Account.id.in_(your subquery)). When I do it that way, I get crazy SQL and an error. Using Account.accountid to shorten the SQL: q0 =

[sqlalchemy] Re: Best way to count( some_relation )

2009-01-26 Thread Jon Nelson
On Mon, Jan 26, 2009 at 7:05 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Jan 26, 2009, at 7:31 PM, Jon Nelson wrote: I assumed it was a bug due to the presence of a python-style string substitution. ... another option is sess.query(Account).filter(Account.id.in_(your subquery

[sqlalchemy] Best way to count( some_relation )

2009-01-26 Thread Jon Nelson
Let's assume I have a 1:many relationship between Accounts and Users. What I want (for example) is a list of Accounts with 1 User. Ideally, I'd do this: Account.query().filter( len(Account.users) 1 ).all() but of course that doesn't work. Instead of describing the myriad ways I've tried, I

[sqlalchemy] deferred column_property bug in 0.5.1?

2009-01-23 Thread Jon Nelson
I was debugging some stuff recently and noticed different behavior in one of my applications than I was expecting. The behavior is the undesirable execution of some sql. The sql is used to populate the value of a column_property. The column_property has been deferred, however, and the property

[sqlalchemy] Re: cascades and many-to-many

2009-01-20 Thread Jon Nelson
On Tue, Jan 20, 2009 at 4:26 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Jan 19, 2009, at 7:08 PM, Michael Bayer wrote: relation, or add a flag such as single_parent=True, something like that, since technically we should be doing something similar for manytoone as well. OK,

[sqlalchemy] Re: postgres autocommit

2009-01-09 Thread Jon Nelson
An alternate solution is to use begin rollback for statements that (aren't supposed to) update data, like (most) select statements. That's even cheaper than calling commit usually. On Fri, Jan 9, 2009 at 5:05 PM, Randall Smith rand...@tnr.cc wrote: SA, without a transaction in progress

[sqlalchemy] Re: SQLAlchemy Sphinx Documentation Preview

2008-12-05 Thread Jon Nelson
The searching is a bit weird. If I search for Adjacency I get no results. If I search for adjacency (all lower case) I get results, the first of which has an upper-cased Adjacency. Otherwise they look nice and I'm sure will look nicer-yet as time goes on! -- Jon