[sqlalchemy] Upgrading from 1.3.23 to 1.4.x subquery seems stricter

2022-05-28 Thread gbr
In SQLA 1.3.x, I used to follow this pattern to construct a query: ``` def load_something(... sort=False): qry = select(columns=..., from_obj=...) if sort: qry = qry.order_by(desc(qry.c.created_on)) if ... qry = qry... ``` but in 1.4.0 and 1.4.37 (I guess the versions in

[sqlalchemy] Locking method used in SQLAlchemy (postgres)

2020-06-29 Thread gbr
Hi, I'm using SQLAlchemy's Core to interface a postgres database (via psycopg2) component alongside Flask-SQLAlchemy in a Flask app. Everything was working fine until I recently discovered what seems to be a deadlock state which is caused by two queries locking each other (at least that's my

Re: Python 3.7 - RuntimeError: generator raised StopIteration

2019-06-28 Thread gbr
Indeed, I was using version 1.0.9 and didn't realise that this wasn't an issue with alembic. Thanks for the quick response. On Friday, 28 June 2019 22:30:49 UTC+2, Mike Bayer wrote: > > > > On Fri, Jun 28, 2019, at 4:01 PM, gbr wrote: > > I've upgraded my applica

Python 3.7 - RuntimeError: generator raised StopIteration

2019-06-28 Thread gbr
I've upgraded my application to Python 3.7 and to the latest version of Alembic which triggers an exception when `context.get_current_revision()` is called. ``` File "app.py", line 395, in check_database_version current_rev = context.get_current_revision() File

[sqlalchemy] Re: a Python-side value or SQL expression is required

2016-01-19 Thread gbr
for taking the time to respond (and of course for creating such a great library). On Monday, 18 January 2016 18:23:04 UTC+11, gbr wrote: > > I've upgraded from a SQLA version 0.9.x to 1.0.9. Previously, I did the > following when inserting new records: > > - Column('flag', Boolean,

[sqlalchemy] Re: a Python-side value or SQL expression is required

2016-01-18 Thread gbr
resolving this without relying on buggy (and potentially not maintained) behaviour? Thanks for your help. On Monday, 18 January 2016 18:23:04 UTC+11, gbr wrote: > > I've upgraded from a SQLA version 0.9.x to 1.0.9. Previously, I did the > following when inserting new records: > > - Colu

[sqlalchemy] a Python-side value or SQL expression is required

2016-01-17 Thread gbr
I've upgraded from a SQLA version 0.9.x to 1.0.9. Previously, I did the following when inserting new records: - Column('flag', Boolean, server_default=sql.expression.false()) I didn't set those columns locally and didn't include them in the insert statement when I wanted them to be False -

Re: [sqlalchemy] returned_defaults fails after upgrading from 0.9.4

2015-11-01 Thread gbr
aults implies only a single row > INSERT which is not the case for INSERT from SELECT. > > > > > On 11/01/2015 01:29 AM, gbr wrote: > > I've just tried to upgrade from 0.9.4 to the latest 1.0.9 version (yes, > > I'm late) and am running into some problems. Most notably, &

[sqlalchemy] returned_defaults fails after upgrading from 0.9.4

2015-10-31 Thread gbr
I've just tried to upgrade from 0.9.4 to the latest 1.0.9 version (yes, I'm late) and am running into some problems. Most notably, `returned_defaults` from an insert query does not seem to work as before. This is part of my code: new_record = select([user_id, parent_id, 1 +

[sqlalchemy] insert().from_select() does not set default values

2014-10-10 Thread gbr
Given this example, I would expect that in both cases the default value of user.admin gets set. from sqlalchemy import * from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker, scoped_session engine = create_engine('sqlite:///:memory:', echo=True) Base =

Re: [sqlalchemy] insert().from_select() does not set default values

2014-10-10 Thread gbr
instead. On Oct 10, 2014, at 5:12 AM, gbr doub...@directbox.com javascript: wrote: Given this example, I would expect that in both cases the default value of user.admin gets set. from sqlalchemy import * from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import

Re: [sqlalchemy] insert().from_select() does not set default values

2014-10-10 Thread gbr
change to `server_default`... On Saturday, 11 October 2014 09:28:32 UTC+11, gbr wrote: I didn't know 1.0 was out already. How can I upgrade to it? `pip` and `easy_install` still install 0.9.7... On Saturday, 11 October 2014 08:50:05 UTC+11, Michael Bayer wrote: I’ve implemented this feature

Re: [sqlalchemy] insert().from_select() does not set default values

2014-10-10 Thread gbr
for the most foolproof system of putting in default values, because the database does it. Is the “SET DEFAULT” thing there the old or the new database? On Oct 10, 2014, at 6:41 PM, gbr doub...@directbox.com javascript: wrote: The weird thing is that this problem only arose when I wanted to create

Re: How to determine whether Alembic is active

2014-06-03 Thread gbr
to throw out Flask-SqlAlchemy and see how it goes, but would like to find an easier way first). Any suggestions are appreciated. On Friday, May 16, 2014 5:02:57 PM UTC+10, gbr wrote: True. I should have modified def run_migrations_online(): Run migrations in 'online' mode

Re: [sqlalchemy] Adding where clause to existing SELECT without wrapping SELECT

2014-05-21 Thread gbr
in here to extract the column reference of `k`? a.add(column == v) return sel.where(a) On Wednesday, May 21, 2014 6:45:21 AM UTC+10, Michael Bayer wrote: On May 19, 2014, at 9:12 PM, gbr doub...@directbox.com javascript: wrote: I'm trying to modify a select statement which

Re: [sqlalchemy] Adding where clause to existing SELECT without wrapping SELECT

2014-05-20 Thread gbr
the column you want to filter to. -Ryan Kelly On Mon, May 19, 2014 at 9:12 PM, gbr doub...@directbox.com javascript: wrote: I'm trying to modify a select statement which is fairly complex and which is created in a function that I don't want to modify. It is returned from

[sqlalchemy] Adding where clause to existing SELECT without wrapping SELECT

2014-05-19 Thread gbr
I'm trying to modify a select statement which is fairly complex and which is created in a function that I don't want to modify. It is returned from this function and I'd like to add more WHERE clauses by just referencing the returned select statement. How can I do this without causing SQLA

Re: How to determine whether Alembic is active

2014-05-16 Thread gbr
13, 2014, at 8:41 AM, gbr doub...@directbox.com javascript: wrote: In some Alembic upgrade scripts, I need to use application sessions to make use of some code that requires these sessions. To avoid deadlocks from blocking transactions I use the following lines to transparently call

Re: [sqlalchemy] Nested select from insert into select union select

2014-05-09 Thread gbr
. a workaround might be to monkeypatch select() for now: sel = select( [b_id, product.c.id], ).union( select([b_id, s_id]) ) sel.select = lambda : sel On May 8, 2014, at 6:27 PM, gbr doub...@directbox.com javascript: wrote: So what can I do? I'm using postgres 9.3 The error message I

[sqlalchemy] Nested select from insert into select union select

2014-05-08 Thread gbr
I don't quite understand why SQLA generates this query. For some reason it wraps the union part into a separate select. How can I avoid this? b_id = 2 s_id = 3 id = product.c.id sel = select( [b_id, product.c.id], ).union( select([b_id, s_id]) ) ins = insert(product).from_select([

Re: [sqlalchemy] Nested select from insert into select union select

2014-05-08 Thread gbr
with a raw UNION like that, we can loosen this restriction to apply to union-orinented selects as well but it’s not clear if some backends might have problems with it. On May 8, 2014, at 4:28 AM, gbr doub...@directbox.com javascript: wrote: I don't quite understand why SQLA generates this query

Re: [sqlalchemy] exists() adding additional from clause

2014-05-06 Thread gbr
can I get SQLA to create the query I want? On Thursday, May 1, 2014 8:20:30 AM UTC+10, gbr wrote: correlate_except(table) did the trick. I thought I had tried it before, but something must have gone wrong. Now it works. Thanks for your help. On Wednesday, April 30, 2014 11:53:04 PM UTC+10

Re: [sqlalchemy] exists() adding additional from clause

2014-05-06 Thread gbr
. This behaviour fairly unexpected though. Is this somehow mentioned in the documentation? An example like this would be great (if not already existing)... On Tuesday, May 6, 2014 7:07:16 PM UTC+10, gbr wrote: I'm running into a similar problem again. This time, correlate_except doesn't change anything

[sqlalchemy] exists() adding additional from clause

2014-04-30 Thread gbr
For some reason, an exists() where clause which is meant to refer to an outer element is pulling the outer element's table into the query. What I need is as follows SELECT anon1.id, anon1.value from ( SELECT DISTINCT ON (pp.id) pp.id AS id, pp.rev_id AS rev_id, pp.deleted FROM prod as pp

Re: [sqlalchemy] exists() adding additional from clause

2014-04-30 Thread gbr
correlate_except(table) did the trick. I thought I had tried it before, but something must have gone wrong. Now it works. Thanks for your help. On Wednesday, April 30, 2014 11:53:04 PM UTC+10, Michael Bayer wrote: On Apr 30, 2014, at 8:37 AM, gbr doub...@directbox.com javascript: wrote

Re: Init alembic at specific revision

2014-03-29 Thread gbr
Exactly what I was looking for - thanks. On Sunday, March 30, 2014 10:43:12 AM UTC+11, Felix Schwarz wrote: Am 29.03.2014 23:33, schrieb gbr: There's one thing though that I haven't been able to work out yet (maybe this feature doesn't exist). How about the stamp() command? http

Re: [sqlalchemy] generate_series?

2014-03-05 Thread gbr
@compiles in order to render. I might have given someone that recipe at some point. On Mar 4, 2014, at 1:39 AM, gbr doub...@directbox.com javascript: wrote: I know this is an old thread, but there isn't much on the web around generate_series and SQLA, so I thought I might revive

Re: [sqlalchemy] Re: generate_series?

2014-03-03 Thread gbr
I know this is an old thread, but there isn't much on the web around generate_series and SQLA, so I thought I might revive it. One of the suggestion was to use: s = func.generate_series(4,5,6).alias(cols=['a']) select([func.current_date() + s.c.a]) Unfortunately, alias doesn't take a `cols`

Re: [sqlalchemy] Mimik joinedload for core tables/queries

2013-09-11 Thread gbr
, 2013, at 11:03 PM, gbr doub...@directbox.com javascript: wrote: Thanks. That's quite an interesting piece of code. There's a bit of magic happening in this code and it's not quite compatible for my use case (use of queries instead of tables, no ORM mapping), so allow me to ask some questions

Re: [sqlalchemy] Mimik joinedload for core tables/queries

2013-09-11 Thread gbr
the key in `collection` then? Or maybe I didn't understand when the actual query is being executed... On Thursday, September 12, 2013 11:54:20 AM UTC+10, gbr wrote: `select_entity_from` finally did the trick. I did qry = session.query(child_query).select_entity_from(parent_query).join

Re: [sqlalchemy] Mimik joinedload for core tables/queries

2013-09-11 Thread gbr
Never mind. I think I know how this works now. I didn't realise that `child_q` gets executed as soon as it's iterated (despite your comment). Also, the `child.parent_id` is used as key to fill the dict... On Thursday, September 12, 2013 2:54:47 PM UTC+10, gbr wrote: I've still got a question

Re: [sqlalchemy] Mimik joinedload for core tables/queries

2013-09-03 Thread gbr
3, 2013 1:39:44 AM UTC+10, Michael Bayer wrote: On Aug 31, 2013, at 7:33 PM, gbr doub...@directbox.com javascript: wrote: On Sunday, September 1, 2013 8:19:24 AM UTC+10, Michael Bayer wrote: Let me add a bit of information. I assumed the behaviour would be the same in ORM (actually, when

[sqlalchemy] Re: Optimization my table (unicode disccussion)

2013-09-01 Thread gbr
What do you mean by optimize? What's the desired goal of your optimisation, or in other words: what's not optimal at the moment? Looking at your table, I can think of (guess) a few things I'd do different (namely normalisation http://en.wikipedia.org/wiki/Database_normalization). But whether

Re: [sqlalchemy] Mimik joinedload for core tables/queries

2013-08-31 Thread gbr
On Sunday, September 1, 2013 8:19:24 AM UTC+10, Michael Bayer wrote: On Aug 31, 2013, at 1:16 AM, gbr doub...@directbox.com javascript: wrote: Could anyone provide some suggestions on where to look in the SQLA code (or even an example, or some general thoughts) for how to perform

[sqlalchemy] Mimik joinedload for core tables/queries

2013-08-30 Thread gbr
Could anyone provide some suggestions on where to look in the SQLA code (or even an example, or some general thoughts) for how to perform a `joinedload` as the ORM does it for Core tables (or actually an already executed query which has unresolved references which I'd like to load in a

Re: [sqlalchemy] Possible bug in select.append_whereclause()?

2013-08-29 Thread gbr
, but is there more documentation on this and other parts of the query?)... Many thanks for the swift response (and SQLAlchemy for that matter :)). On Thursday, August 29, 2013 9:46:02 PM UTC+10, Michael Bayer wrote: On Aug 28, 2013, at 11:48 PM, gbr doub...@directbox.com javascript: wrote

[sqlalchemy] Possible bug in select.append_whereclause()?

2013-08-28 Thread gbr
Hi, Before spamming the issue tracker and since I'm new to SQLAlchemy and may have misunderstood how to use `append_whereclause()`, I thought I seek confirmation on this mailing list. The code: def test_append_whereclause(self): url = 'localhost' username = 'donald'

Re: [sqlalchemy] Possible bug in select.append_whereclause()?

2013-08-28 Thread gbr
to compile the WHERE clause of query means we look at query.c.id which means we must render the table query which is how it cycles. Why does it need to compile the whole query when I just want to use than column name of the query? What it seems like you're looking to do is

[sqlalchemy] Re: Possible bug in select.append_whereclause()?

2013-08-28 Thread gbr
You're right. These two queries work fine. However, I don't have access to `location.c.id` which is why I hoped to be able to use attributes of `query`. I've copied the example out of a bigger program which mixes Core and ORM features (hence the use of sessionmaker). On Thursday, August 29,