Commit Graph

111 Commits

Author SHA1 Message Date
Greg Jarzab 7f5e9e733c Support for Create Table As
Added support for the SQL ``CREATE TABLE ... AS SELECT`` construct via the
new :class:`_sql.CreateTableAs` DDL construct and the
:meth:`_sql.SelectBase.into` method. The new construct allows creating a
table directly from the results of a SELECT statement, with support for
options such as ``TEMPORARY`` and ``IF NOT EXISTS`` where supported by the
target database.  Pull request courtesy Greg Jarzab.

Fixes: #4950
Closes: #12860
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12860
Pull-request-sha: 7de8a109b8

Change-Id: Id9c8e4a3c520ffc61de1e48e331b6220e3d52fc9
2025-10-25 14:24:46 -04:00
Mike Bayer 9a6854223c fix tests for aggregate_order_by
forgot this doesnt work on sqlite older than 3.44

Change-Id: Icebc2ffaceb078a436a8f61ba583bc05b77f680d
2025-09-19 15:18:39 -04:00
Reuven Starodubski 459ebc668a Add FunctionElement.aggregate_order_by
Added new generalized aggregate function ordering to functions via the
:func:`_functions.FunctionElement.aggregate_order_by` method, which
receives an expression and generates the appropriate embedded "ORDER BY" or
"WITHIN GROUP (ORDER BY)" phrase depending on backend database.  This new
function supersedes the use of the PostgreSQL
:func:`_postgresql.aggregate_order_by` function, which remains present for
backward compatibility.   To complement the new parameter, the
:paramref:`_functions.aggregate_strings.order_by` which adds ORDER BY
capability to the :class:`_functions.aggregate_strings` dialect-agnostic
function which works for all included backends. Thanks much to Reuven
Starodubski with help on this patch.

Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com>
Fixes: #12853
Closes: #12856
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12856
Pull-request-sha: d93fb591751227eb1f96052ea3ad449f511f70b3

Change-Id: I8eb41ff2d57695963a358b5f0017ca9372f15f70
2025-09-19 09:38:57 -04:00
Mike Bayer d37d56c1ad Fix PostgreSQL JSONB subscripting regression with functions
Fixed regression in PostgreSQL dialect where JSONB subscription syntax
would generate incorrect SQL for JSONB-returning functions, causing syntax
errors. The dialect now properly wraps function calls and expressions in
parentheses when using the ``[]`` subscription syntax, generating
``(function_call)[index]`` instead of ``function_call[index]`` to comply
with PostgreSQL syntax requirements.

Fixes: #12778
Change-Id: If1238457e6bba6a933023b26519a41aa5de4dbcd
2025-08-04 15:06:47 -04:00
Mike Bayer 5b5db1f5f3 note that SQL parenthesis are based on precedence
References: #12708
Change-Id: I2401e92c936eb01a64ad6896a86faec1c205bc08
2025-07-02 09:18:28 -04:00
Federico Caselli fb5e64c51a add example to update from that uses values
Change-Id: Ic02a722be9a30851a87e0da4759c728e86fb22c8
References: #11768
2025-06-24 17:43:43 -04:00
Christopher Jones 855d03cc15 Update Oracle dialect doc, mostly to prefer python-oracledb
### Description

Small updates for Oracle Database dialect documentation.

- prefer python-oracledb over cx_Oracle
- Prefer the product name 'Oracle Database' over the company name 'Oracle'
- update links
- modernize

This is a refresh of existing content.

I decided the apparently now duplicated sections between cx_Oracle and python-oracledb were justified for clarity due to the inevitable differences.

This pull request is:

- [x] A documentation / typographical / small typing error fix
	- Good to go, no issue or tests are needed

**Have a nice day!**

Closes: #12078
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12078
Pull-request-sha: 7c4dcf9403

Change-Id: I3678976f5524ee164dc31b3122b224ae37060b71
2024-11-12 17:28:38 -05:00
Mike Bayer e9d3e49601 ensure intro to "functions have types" is not misleading
make sure it's clear that there is normally not a return type
for SQL functions

Fixes: #11578
Change-Id: Ia0b66e7fe685dad427822345dd232eb47a0fc44f
2024-07-06 12:24:51 -04:00
lonkeknol 82d14a7515 Docs: simplify language in getting a connection & committing changes
### Description
Simplifies language use in [Getting a Connection](https://docs.sqlalchemy.org/en/20/tutorial/dbapi_transactions.html#getting-a-connection) and [Committing Changes](https://docs.sqlalchemy.org/en/20/tutorial/dbapi_transactions.html#committing-changes)

### Checklist
This pull request is:

- [x] A documentation / typographical / small typing error fix
	- Good to go, no issue or tests are needed
- [ ] A short code fix
	- please include the issue number, and create an issue if none exists, which
	  must include a complete example of the issue.  one line code fixes without an
	  issue and demonstration will not be accepted.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.   one line code fixes without tests will not be accepted.
- [ ] A new feature implementation
	- please include the issue number, and create an issue if none exists, which must
	  include a complete example of how the feature would look.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.

**Have a nice day!**

Closes: #11542
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/11542
Pull-request-sha: d706e69fb6

Change-Id: I7788f2a16a5127b3c9623f7b00f06f649b04e0fb
2024-06-28 12:27:33 -04:00
lonkeknol fc2cb4496d Docs: simplify language use for "Working with Transactions and the DBAPI"
### Description
This is my first pull request to sqlalchemy. It changes the writing style of two paragraphs in the unified tutorial [here](https://docs.sqlalchemy.org/en/20/tutorial/dbapi_transactions.html#working-with-transactions-and-the-dbapi). My goals were to.
1. Make them easier to read
2. Not change the meaning of the text.
3. Get feedback on whether this type of contribution is considered useful for sqlalchemy.

If this is a useful type of contribution, it might be good to discuss some general guidelines for me to adhere to as I continue. For instance:
- Prefer using present simple tense
- Remove superfluous words where possible
- Keep the pull requests to one or two h2 sections at a time, to make the review easier

### Checklist
This pull request is:

- [x] A documentation / typographical / small typing error fix
	- Good to go, no issue or tests are needed
- [ ] A short code fix
	- please include the issue number, and create an issue if none exists, which
	  must include a complete example of the issue.  one line code fixes without an
	  issue and demonstration will not be accepted.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.   one line code fixes without tests will not be accepted.
- [ ] A new feature implementation
	- please include the issue number, and create an issue if none exists, which must
	  include a complete example of how the feature would look.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.

I'm curious to hear what you all think. **Have a nice day!**

Closes: #11541
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/11541
Pull-request-sha: 3179690e6a

Change-Id: I9b47f6ce4fd00c44c4b0e19957acf250f5e46d2f
2024-06-27 09:03:30 -04:00
Andreas Deininger 1f6a129d80 Fixing typos (#11105) 2024-03-11 22:40:14 +01:00
acceptacross 64b661d705 chore: remove repetitive words (#11134)
Signed-off-by: acceptacross <csqcqs@gmail.com>
2024-03-11 22:01:42 +01:00
Federico Caselli f0537442eb Add support for preserve_rowcount execution_option
Added new core execution option
paramref:`_engine.Connection.execution_options.preserve_rowcount`
to unconditionally save the ``rowcount`` attribute from the cursor in the
class:`_engine.Result` returned from an execution, regardless of the
statement being executed.
When this option is provided the correct value is also set when
an INSERT makes use of the "insertmanyvalues" mode, that may use
more than one actualy cursor execution.

Fixes: #10974
Change-Id: Icecef6b7539be9f0a1a02b9539864f5f163dcfbc
2024-03-03 17:58:12 -05:00
Federico Caselli 1e099d1a85 clarify example in orm tutorial
Change-Id: Ib6f9a7ce0beacda43ccd6d3c7750778ed3333b38
2024-02-14 20:55:57 +01:00
Umer Zia 3a4e9063e4 Improve formatting of data_select.rst (#10931) 2024-02-06 18:56:09 +01:00
mike bayer 34802a204f Merge "2.1 setup / initial dependency/min version change" into main 2023-11-06 23:03:44 +00:00
Sebastián Ramírez e00215cfcd Fix syntax typo in doc/build/tutorial/data_select.rst (#10590) 2023-11-06 21:01:51 +01:00
Mike Bayer e93a5e890d 2.1 setup / initial dependency/min version change
this includes setup.cfg changes for asyncio and
3.8 min support.  it doesnt have any code changes in support
of these adjusments.

Fixes: #10197
Fixes: #10357

Change-Id: Ic4569c770d1b893a067a9a5dfe13a6e28aaf47fa
2023-11-06 14:10:32 -05:00
AmirSoroush 18d6b50b65 Doc: Update doc/build/tutorial/data_select.rst (#10506)
Removed an extra "that" in a sentence.
2023-10-19 18:44:26 +02:00
Eric Hanchrow 0df9759b73 Revise / rewrite sentences that use the phrase "referred towards"
Comments by Mike <mike_mp@zzzcomputing.com>:

"Referred towards" is not correct English and can be replaced directly
with "referred to".  However, this then introduces a dangling
preposition to sentences which I don't think is appropriate for this
style of writing.  So instead, use phrases like "known as",
"references", "to which X refers".

To help me identify dangling prepositions I made use of ChatGPT,
here's the log of how that transpired:
https://chat.openai.com/share/60d42ff4-c1ac-4232-893a-415c2b6d7320

Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com>
Closes: #10210
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/10210
Pull-request-sha: 5d30e79c14

Change-Id: Ib6a98e5be441f5b25d3929a2efb7d873bcfef98e
2023-09-20 18:18:29 -04:00
Mike Bayer b38702ee9d fix typo
Change-Id: I55855508fdf7e0f0af346f4f1f79292d83784aea
2023-08-04 10:01:07 -04:00
Federico Caselli e99fc16fbd fix typo in sphinx target introduced in bd290c4329
Change-Id: Ie085696fca3ce44ad7af611246fc8be45abbc433
2023-06-13 21:19:51 +02:00
Federico Caselli bd290c4329 various minor docs improvements
Change-Id: I5e7332047c03260792bf990aafd0ef4e15f5f082
2023-06-12 22:28:25 +02:00
mike bayer c84b3bf198 Merge "add deterministic imv returning ordering using sentinel columns" into main 2023-04-21 16:51:19 +00:00
Mike Bayer cf6872d3bd add deterministic imv returning ordering using sentinel columns
Repaired a major shortcoming which was identified in the
:ref:`engine_insertmanyvalues` performance optimization feature first
introduced in the 2.0 series. This was a continuation of the change in
2.0.9 which disabled the SQL Server version of the feature due to a
reliance in the ORM on apparent row ordering that is not guaranteed to take
place. The fix applies new logic to all "insertmanyvalues" operations,
which takes effect when a new parameter
:paramref:`_dml.Insert.returning.sort_by_parameter_order` on the
:meth:`_dml.Insert.returning` or :meth:`_dml.UpdateBase.return_defaults`
methods, that through a combination of alternate SQL forms, direct
correspondence of client side parameters, and in some cases downgrading to
running row-at-a-time, will apply sorting to each batch of returned rows
using correspondence to primary key or other unique values in each row
which can be correlated to the input data.

Performance impact is expected to be minimal as nearly all common primary
key scenarios are suitable for parameter-ordered batching to be
achieved for all backends other than SQLite, while "row-at-a-time"
mode operates with a bare minimum of Python overhead compared to the very
heavyweight approaches used in the 1.x series. For SQLite, there is no
difference in performance when "row-at-a-time" mode is used.

It's anticipated that with an efficient "row-at-a-time" INSERT with
RETURNING batching capability, the "insertmanyvalues" feature can be later
be more easily generalized to third party backends that include RETURNING
support but not necessarily easy ways to guarantee a correspondence
with parameter order.

Fixes: #9618
References: #9603
Change-Id: I1d79353f5f19638f752936ba1c35e4dc235a8b7c
2023-04-21 11:30:40 -04:00
Tim Stewart bf3a395e8f fix typo ('resemblence' -> 'resemblance') (#9674) 2023-04-20 19:42:02 +02:00
Chris 24587f2009 Update data_select.rst (#9616)
Fix literal text in example
2023-04-07 22:07:54 +02:00
Tom Wolfskämpf c7ce7ff022 docs: 📚 fix duplicate word typo (#9539) 2023-03-25 18:45:37 +01:00
Mike Bayer 42b3b80fae add tip that reflection is not necessary for an existing database
a new user spent many days misled by this paragraph thinking
they were required to use reflection for an existing database.

Change-Id: I4c6757b931481db7a8d4202334382143e1491935
2023-03-21 13:40:36 -04:00
Mike Bayer 8d5986fafd additional consistency for ORM/Core in tutorial
* Make sure we have blue borders for all sections
* rewrite "blue border" text, refer to textual means of determining
  subject matter for a section; "blue borders" are not a primary
  source of information
* Add some more intro text that was missing

Change-Id: I4d599e13d23bad8bb3c199a11afb53e3e9100c59
References: #9450
2023-03-08 10:10:14 -05:00
Viicos 92159a1728 Remove duplicate word in tutorial (#9420) 2023-03-03 22:46:49 +01:00
easy_markie_tee 9d9e47fe93 Fix Typo In Tutorial (#9399)
Missing a word on the page `Working with Database Metadata`.
First paragraph under section 'Setting up MetaData with Table objects'.
"...the database which we query from is know [as] a table."

Co-authored-by: markie tee <cassette.head@gmail.com>
2023-03-01 22:51:43 +01:00
Harry Lees 961f076230 Unify doc typing
### Description
<!-- Describe your changes in detail -->

Fixes #9168

This PR replaces common occurrences of [PEP 585](https://peps.python.org/pep-0585/) style type annotations with annotations compatible with older versions of Python.

I searched for instances of the following supported types from the PEP and replaced with their legacy typing couterparts.

* tuple # typing.Tuple
* list # typing.List
* dict # typing.Dict
* set # typing.Set
* frozenset # typing.FrozenSet
* type # typing.Type

```
grep -r "list\[.*\]" ./build --exclude-dir="./build/venv/*" --exclude-dir="./build/output/*" --exclude="changelog_[0-9]*\.rst"
```

I excluded changelog files from being altered, I think some of these could be changed if necessary but others are likely to require manual checking as the change may target the new typing style specifically.

For any examples that included imports, I tried to ensure that the correct typing imports were included and properly ordered.

### Checklist
<!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once)

-->

This pull request is:

- [x] A documentation / typographical error fix
	- Good to go, no issue or tests are needed
- [ ] A short code fix
	- please include the issue number, and create an issue if none exists, which
	  must include a complete example of the issue.  one line code fixes without an
	  issue and demonstration will not be accepted.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.   one line code fixes without tests will not be accepted.
- [ ] A new feature implementation
	- please include the issue number, and create an issue if none exists, which must
	  include a complete example of how the feature would look.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.

Closes: #9198
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9198
Pull-request-sha: 05ad4651b5

Change-Id: I41b93b3dee85f9fe00cfbb3d3eb011212795de29
2023-01-31 19:45:48 +00:00
Mike Bayer e82a5f19e1 reword INSERT explanation
Change-Id: I08460f0a77131c8c1406c3496e9d64a5a26bf6ff
2023-01-19 09:43:19 -05:00
Federico Caselli 8b4b26e709 avoid confusion in rst comment
Change-Id: I6e971f7445ae19f73097516b58776ab05a5371f1
2023-01-18 23:02:48 +01:00
Mike Bayer 6da2f72b11 super-fine pass through the metadata tutorial
try to keep the wordiness down here, using sidebars
and topics for non-essential information.   Sphinx seems
to read out attrs from under TYPE_CHECKING sections now
so link out the attrs in DeclarativeBase w/ docstrings,
not sure why we didn't think of this earlier.  looks great

Change-Id: Ib2e07e3606185998561c2d77b2564fd3eddb4d75
2023-01-15 13:11:38 -05:00
Mike Bayer 48eed9eb9c fix orm-header for standalone
Change-Id: I20e7f8ad5800c2ce5cdc9645c4dbe66f53b8cdf8
2023-01-15 11:28:49 -05:00
Mike Bayer 0c5faf37c2 fix typo
Change-Id: I273459175a3c55290b1f6c28f656ed9c4db17ccf
2023-01-13 14:31:28 -05:00
Federico Caselli b04b7527ed Make the custom type map more discoverable
Change-Id: Id6cdaddad83aa93508e256e54010a6c53218b717
2023-01-13 10:40:19 -05:00
Federico Caselli 06d584ad4b Fixes related to improved sql formatting
Follow up of I07b72e6620bb64e329d6b641afa27631e91c4f16

Change-Id: I1f61974bf9cdc3da5317e546d4f9b649c2029e4d
2023-01-12 23:03:03 +01:00
Federico Caselli dce11383f8 Improve sql formatting
change {opensql} to {printsql} in prints, add missing markers

Change-Id: I07b72e6620bb64e329d6b641afa27631e91c4f16
2023-01-11 20:24:29 +01:00
Mike Bayer 2f09374d44 remove anchor removed by mistake
Change-Id: I20e196f63c8cea9cd805501ab174cab320575b05
2023-01-09 15:20:39 -05:00
Mike Bayer c30a48604c fix inconsistent title level
Change-Id: I954818fdf9f5b56a895dbfdaf191c4c5867b574f
2023-01-09 15:16:50 -05:00
Mike Bayer 1e7d452836 more thoughts on tutorial presentation of ORM /Core
Change-Id: Iaa0c160e3f8285f1ca989dcb12b86de15ea82f03
2023-01-04 15:17:26 -05:00
Mike Bayer 72268e9387 tutorial updates re: Core /ORM commonality
updates for Insert / bulk insert, executemanyvalues,
as well as beginning to describe Table / declared class more
closely together, mentioning typing support.

Fixed a long-standing issue where sphinx would complain about
the Insert symbol being ambiguous.

Change-Id: Id4cc09b9581e8fa39c9c00bc8f229636e626e9bc
2023-01-03 18:21:25 -05:00
Mike Bayer 3d8d366e1b Oracle COLUMN_VALUE is a column name, not a keyword
Fixed issue in Oracle compiler where the syntax for
:meth:`.FunctionElement.column_valued` was incorrect, rendering the name
``COLUMN_VALUE`` without qualifying the source table correctly.

Fixes: #8945
Change-Id: Ia04bbdc68168e78b67a74bb3834a63f5d5000627
2022-12-07 17:28:49 -05:00
Andy Garfield 36954a3dbb Small tutorial rewording
The language is this sentence took me a few reads to understand. This is just a rewording.
2022-11-15 11:28:58 -05:00
Mike Bayer 80372f6c4c further 2.0 modernizations
biggest change here is the old tutorials were removed from the
TOC and some additional links to them have been corrected.

Change-Id: I79b878a946422eac24ed2449b440fc5d556576c4
2022-10-13 10:13:01 -04:00
Mike Bayer cfd5b3e78f fixes for doc builds
* requirements needs typing_extensions
* update all "future=True" references to be appropriate to 2.0

Change-Id: I2eeb0ae65afdb587f21aeb0020f1d8a292f67c21
2022-10-13 09:12:04 -04:00
Mike Bayer d4b8b41832 update executemany for new features
also fixes issue in format_docs_code which didn't work with
pre-commit for more than one file.  will backport

Fixes: #8597
Change-Id: I21b2625514987b1cd90f7c00f06e72e57e257390
2022-10-11 15:29:15 -04:00