Hi Mike,
When using Core, we can do a bulk insert and bulk return with Postgresql
trivially:
from sqlalchemy import table, column
t = table('foo', column('id'), column('bar')
ins = t.insert().values([{'bar': 'a'}, {'bar': 'b'}]).returning(foo.id)
results = conn.execute(ins)
Hi Mike,
If I understand correctly, you want to work with raw sql and don't want any
ORM getting in your way. I'm the same way, and it is trivial to use
SQLAlchemy Core for this purpose.
results = conn.execute(text('select foo, bar from
baz')).mappings().fetchall() # mappings().fetchall()
Hi Mike,
That's much more concise, thank you.
Previously I have always accessed the `_asdict()` private member.
Thanks and best regards,
Matthew
On Thursday, January 12, 2023 at 11:00:58 AM UTC-8 Mike Bayer wrote:
>
>
> On Thu, Jan 12, 2023, at 1:46 PM, mkmo...@gmail.com wrote:
&g
())
something else?
Thanks and best regards,
Matthew
On Monday, January 9, 2023 at 6:00:08 PM UTC-8 Mike Bayer wrote:
>
>
> On Mon, Jan 9, 2023, at 8:50 PM, mkmo...@gmail.com wrote:
>
> Hello,
>
> It looks like in 2.0 we can no longer treat a row.Row as a dict. I have a
Hello,
It looks like in 2.0 we can no longer treat a row.Row as a dict. I have a
few cases where I want to do this, such as when I need to get a list of
columns, or when I don't know the column name in advance.
rows = conn.execute(select(t.c.foo)).fetchall()
rows[0].keys() # Not
Apologies if this is in the documentation, but I was not able to find it.
Does SQLAlchemy Core support the MERGE statement?
Thanks and best regards,
Matthew
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide
I'm using the standard connection pool via engine:
engine = sqlalchemy.create_engine('oracle://scott:tiger@foo', ...)
conn1 = engine.connect()
conn2 = engine.connect()
I want to dispose and recreate the pool in a web environment.
All new threads that connect should get a new
if match:
> text = re.sub(r"BULK COLLECT INTO (.*)", "", text)
> text = text.replace("FROM", f"BULK COLLECT INTO {match.group(1)}
> FROM")
> return text
>
> baz = table('baz', column('foo'), column('bar'))
>
> stmt =
Hello,
I am generating Oracle PLSQL using sqlalchemy core.
I would like to generate the following output:
SELECT foo, bar
BULK COLLECT INTO l_foos
FROM baz;
Is there a mechanism to insert a string after the select column list and
before the FROM?
In sql/compiler.py:visit_select
Thanks!
On Friday, September 16, 2022 at 10:53:59 AM UTC-7 Mike Bayer wrote:
>
>
> On Fri, Sep 16, 2022, at 12:10 PM, mkmo...@gmail.com wrote:
>
> I use the following pattern in my REST APIs, building up the select,
> joins, where conditions, group bys, order bys, depe
I use the following pattern in my REST APIs, building up the select, joins,
where conditions, group bys, order bys, depending on the query parameters
passed in by the user:
selects = [Foo]
joins = [(Bar, Foo.c.id == Bar.c.foo_id)]
where_conditions = [Foo.c.id == request.args['pk']]
As stated in the docs:
> All SQLAlchemy pool implementations have in common that none of them “pre
create” connections - all implementations wait until first use before
creating a connection
Is it possible to warm up, or pre create, the connections in the pool?
When I start my server, the
My apologies, I just saw that I can use the schema key word for this case:
t = table('mytable', column('id'), schema='myschema')
Best regards,
Matthew
On Friday, June 17, 2022 at 11:13:44 AM UTC-7 mkmo...@gmail.com wrote:
> Using a `.` in a table name will cause the table n
Using a `.` in a table name will cause the table name to be quoted.
For example:
from sqlalchemy import table, column
t = table('myschema.mytable', column('id'))
print(select(t.c.id))
Outputs:
SELECT "myschema.mytable".id
FROM "myschema.mytable"
This fails in Oracle
hub.com/sqlalchemy/sqlalchemy/issues/7865
>
> this will allow retunring(User) to send back an instance but there's a lot
> of cases to be worked out.
>
>
>
>
> On Mon, Mar 28, 2022, at 2:05 PM, Mike Bayer wrote:
>
>
>
> On Mon, Mar 28, 2022, at 1:31 PM
print(user.full_name)
Thanks and best regards,
Matthew
On Sunday, March 27, 2022 at 7:28:55 PM UTC-7 Mike Bayer wrote:
>
>
> On Sun, Mar 27, 2022, at 2:56 PM, mkmo...@gmail.com wrote:
>
> Hi Mike,
>
> I'm writing a library that uses SQLAlchemy. The user will pass the librar
.
Is there a public API I can use to take a Core `row` and convert it to an
ORM model?
Thanks and best regards,
Matthew
On Sunday, March 27, 2022 at 11:11:30 AM UTC-7 Mike Bayer wrote:
>
>
> On Sun, Mar 27, 2022, at 2:08 PM, mkmo...@gmail.com wrote:
>
> Hi Mike,
>
>
ring)
>
>
> upd = update(A)
>
> print(select(upd.table).column_descriptions)
>
> i might take a crack at cleaning this up now but the above will get you
> what you need.
>
> On Sat, Mar 26, 2022, at 1:34 PM, mkmo...@gmail.com wrote:
>
> Hello,
>
> How c
Hello,
How can I infer the ORM model class from an update (or insert, or delete)
function result?
upd = update(Project).values(name='foo').where(
Project.id == 1
)
def my_library_function(session, upd):
result = session.execute(upd)
# how to get the Project ORM model here, using
, or list of dict/tuple, similar
to the insert(Project).values API.
Any thoughts?
Best regards,
Matthew
On Wednesday, March 23, 2022 at 6:21:34 AM UTC-7 Mike Bayer wrote:
>
>
> On Tue, Mar 22, 2022, at 2:46 PM, mkmo...@gmail.com wrote:
>
> I would like to do a conditional insert of
I would like to do a conditional insert of a a single row. This is often
useful in a CRUD app for checking permissions and inserting in a single
database call:
INSERT INTO project (name, user_id)
SELECT :name, :user_id
WHERE EXISTS (
SELECT 1
FROM users
WHERE id = :user_id
In sqlalchemy Core, I can get the table and table name from a regular
column by calling `c.table.name`:
from sqlalchemy import table, column
t = table('foo', column('bar'))
assert hasattr(t.c.bar, 'table')
print(t.c.bar.table.name)
However, If I label a column, the label no
wrote:
>
>
> On Fri, Jun 25, 2021, at 11:58 AM, mkmo...@gmail.com wrote:
>
>
> When using PostgreSQL, creating a foreign key on a column in a table does
> not automatically index that column, unlike Oracle or MySQL.
>
> I would like to get SQLAlchemy to automatically creat
When using PostgreSQL, creating a foreign key on a column in a table does
not automatically index that column, unlike Oracle or MySQL.
I would like to get SQLAlchemy to automatically create an index on the same
columns that are specified in a ForeingKeyConstraint.
For example, if I have a
> typing, we still have to support it :) . It has no impact on you as a
> user of the library, you can ignore typing completely and there's no issue
> with that.
>
>
> On Thu, May 13, 2021, at 9:55 AM, mkmo...@gmail.com wrote:
>
> Hi Mike.
>
> Thanks, it make
SQLAlchemy 2.0 seeks to finally remove.As this API is one of the
> most complicated to provide a backwards-compatibility path for, it's taken
> a very long time for us to get there.But here we are.
>
>
>
>
> On Thu, May 13, 2021, at 2:10 AM, mkmo...@gmail.com wrot
Hello,
I am on Sqlalchemy 1.2 and looking to upgrade to 1.4.
I have a lot of Core code that looks like this:
# returns an array of columns
select_fields = make_select_fields(...)
sel = select(select_fields)
Passing an array to select is now deprecated, so I'm planning on changing
that I have
> not really covered. e.g. If I pass in a tuple if (‘tableName’,
> sessionObject) then the code will do the insert/update inside a transaction
> for that session, rather than a direct update etc.
>
> Hope you gain some insight and inspiration. Happy to chat 1:1 if
Hi All,
Some people don't like ORMs and instead use query builders like SQLAlchemy
Core (or even raw SQL text) even for something like a CRUD application.
For sake of argument, let's put aside whether or not this is a good idea.
I'm just curious how one would go about this without copy and
29 matches
Mail list logo