Commit Graph

1682 Commits

Author SHA1 Message Date
Thomas Stephenson e07097ddd2 Fix errors from initial CE run
- fix mypy and linter issues
- expand BitString tests for int and bytes conversion
- Only run BIT test types on postgresql dialect
- Fix problems in `BitString.from_int` and `BitString.from_bytes`
- Add `BitString.to_bytes` method to allow specifying the byte
  length of the returned instances
- Fixed problems testing operators in BIT type tests
2025-05-16 19:31:07 +10:00
Thomas Stephenson 7617485827 10556: Create new BitString subclass for bitstrings for PG drivers
- Added custom `BitString` implementation which inherits from `str`
  and overrides methods and operators appropriately and
  implements the bitwise operations in a manner consistent with
  postgresql. Also exposes class and instance methods ensuring
  instances can be converted to/from `int` and `bytes` sensibly.

- Added default implementations of `bind_processor` and
  `result_processor` to `postgresql.BIT` type to convert `BitString`
  to/from string for PG drivers.

- Override `bind_processor` and `result_processor` in AsyncpgBit
  in order to convert `BitString` to/from `asynpg.BitString`
  in `asyncpg` driver.

- Added support for bitwise comparators to postgresql `BIT` instances

Fixes: 10556
2025-05-15 23:21:49 +10:00
Mike Bayer d689e465ed fix sqlite localtimestamp function
Fixed and added test support for a few SQLite SQL functions hardcoded into
the compiler most notably the "localtimestamp" function which rendered with
incorrect internal quoting.

Fixes: #12566
Change-Id: Id5bd8dc7841f0afab7df031ba5c0854dab845a1d
2025-05-01 09:43:29 -04:00
Federico Caselli 571bb90932 Add pow operator support
Added support for the pow operator (``**``), with a default SQL
implementation of the ``POW()`` function.   On Oracle Database, PostgreSQL
and MSSQL it renders as ``POWER()``.   As part of this change, the operator
routes through a new first class ``func`` member :class:`_functions.pow`,
which renders on Oracle Database, PostgreSQL and MSSQL as ``POWER()``.

Fixes: #8579
Closes: #8580
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8580
Pull-request-sha: 041b2ef474

Change-Id: I371bd44ed3e58f2d55ef705aeec7d04710c97f23
2025-04-22 15:54:50 +00:00
Federico Caselli d0bc9b206d Merge "Support postgresql_include in UniqueConstraint and PrimaryKeyConstraint" into main 2025-04-04 19:04:01 +00:00
Alexander Ruehe 6f8f4a7d62 ensure ON UPDATE test is case insensitive
Fixed regression caused by the DEFAULT rendering changes in 2.0.40
🎫`12425` where using lowercase `on update` in a MySQL server default
would incorrectly apply parenthesis, leading to errors when MySQL
interpreted the rendered DDL.  Pull request courtesy Alexander Ruehe.

Fixes: #12488
Closes: #12489
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12489
Pull-request-sha: b9008f747d

Change-Id: If5281c52415e4ddb6c2f8aee191d2335f6673b35
2025-04-02 11:23:00 -04:00
Denis Laxalde 3b7725dd12 Support postgresql_include in UniqueConstraint and PrimaryKeyConstraint
This is supported both for schema definition and reflection.

Fixes #10665.

Closes: #12485
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12485
Pull-request-sha: 1aabea7b55ece9fc0c6e069b777d4404ac01f964

Change-Id: I81d23966f84390dd1b03f0d13284ce6d883ee24e
2025-04-01 23:20:32 +02:00
Denis Laxalde 588cc6ed8e Cast empty PostgreSQL ARRAY from the type specified to array()
When building a PostgreSQL ``ARRAY`` literal using
:class:`_postgresql.array` with an empty ``clauses`` argument, the
:paramref:`_postgresql.array.type_` parameter is now significant in that it
will be used to render the resulting ``ARRAY[]`` SQL expression with a
cast, such as ``ARRAY[]::INTEGER``. Pull request courtesy Denis Laxalde.

Fixes: #12432
Closes: #12435
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12435
Pull-request-sha: 9633d3c15d

Change-Id: I29ed7bd0562b82351d22de0658fb46c31cfe44f6
2025-03-19 19:32:09 -04:00
Michael Bayer a385bd9b50 Merge "remove deprecated features" into main 2025-03-18 16:12:15 +00:00
Federico Caselli 1ebd8c525b remove deprecated features
Remove feature deprecates in 1.3 and before

Fixes: #12441
Change-Id: Ice3d35ec02988ce94cdeb9db41cb684db2fb5d8d
2025-03-18 09:17:07 -04:00
Michael Bayer fd6c08f403 Merge "add postgresql distinct_on (patch 4)" into main 2025-03-18 13:00:56 +00:00
Michael Bayer 39ef84ee93 Merge "expand paren rules for default rendering, sqlite/mysql" into main 2025-03-18 12:17:26 +00:00
Mike Bayer 5f8ac70996 add postgresql distinct_on (patch 4)
Added syntax extension :func:`_postgresql.distinct_on` to build ``DISTINCT
ON`` clauses. The old api, that passed columns to
:meth:`_sql.Select.distinct`, is now deprecated.

Fixes: #12342
Change-Id: Ia6a7e647a11e57b6ac2f50848778c20dc55eaf54
2025-03-17 15:51:21 -04:00
Mike Bayer 1afb820427 expand paren rules for default rendering, sqlite/mysql
Expanded the rules for when to apply parenthesis to a server default in DDL
to suit the general case of a default string that contains non-word
characters such as spaces or operators and is not a string literal.

Fixed issue in MySQL server default reflection where a default that has
spaces would not be correctly reflected.  Additionally, expanded the rules
for when to apply parenthesis to a server default in DDL to suit the
general case of a default string that contains non-word characters such as
spaces or operators and is not a string literal.

Fixes: #12425
Change-Id: Ie40703dcd5fdc135025d676c01baba57ff3b71ad
2025-03-17 15:02:30 -04:00
Denis Laxalde 39bb17442c Support column list for foreign key ON DELETE SET actions on PostgreSQL
Added support for specifying a list of columns for ``SET NULL`` and ``SET
DEFAULT`` actions of ``ON DELETE`` clause of foreign key definition on
PostgreSQL.  Pull request courtesy Denis Laxalde.

Fixes: #11595
Closes: #12421
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12421
Pull-request-sha: d0394db706

Change-Id: I036a559ae4a8efafe9ba64d776a840bd785a7397
2025-03-17 14:02:24 -04:00
Michael Bayer 1d49add435 Merge "miscellaneous to type dialects" into main 2025-03-17 17:35:20 +00:00
Pablo Estevez 0ee4b08b11 miscellaneous to type dialects
Type of certain methods that are called by dialect, so typing dialects is easier.

Related to https://github.com/sqlalchemy/sqlalchemy/pull/12164

breaking changes:

- Change modifiers from TextClause to InmutableDict, from Mapping, as is in the other classes

Closes: #12231
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12231
Pull-request-sha: 514fe4751c

Change-Id: I29314045b2c7eb5428f8d6fec8911c4b6d5ae73e
2025-03-15 15:12:27 +01:00
Michael Bayer bceff0e9e6 Merge "re-support mysql-connector python" into main 2025-03-14 12:58:23 +00:00
Michael Bayer a8ac6ae23c Merge "Ensure PostgreSQL network address types are not cast as VARCHAR" into main 2025-03-11 18:07:05 +00:00
Denis Laxalde f91e61e5c8 Ensure PostgreSQL network address types are not cast as VARCHAR
Fixed issue in PostgreSQL network types :class:`_postgresql.INET`,
:class:`_postgresql.CIDR`, :class:`_postgresql.MACADDR`,
:class:`_postgresql.MACADDR8` where sending string values to compare to
these types would render an explicit CAST to VARCHAR, causing some SQL /
driver combinations to fail.  Pull request courtesy Denis Laxalde.

Fixes: #12060
Closes: #12412
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12412
Pull-request-sha: 029fda7f2d

Change-Id: Id4a502ebc119775567cacddbabef2ce9715c1a9f
2025-03-11 10:05:39 -04:00
Mike Bayer 21630d2574 consolidate kwargs for "FOR UPDATE OF"
Fixed compiler issue in the PostgreSQL dialect where incorrect keywords
would be passed when using "FOR UPDATE OF" inside of a subquery.

Fixes: #12417
Change-Id: I6255d165e8e719e1786e78aa60ee8e6a95af1dcb
2025-03-11 08:36:18 -04:00
Mike Bayer b056dd2c5a re-support mysql-connector python
Support has been re-added for the MySQL-Connector/Python DBAPI using the
``mysql+mysqlconnector://`` URL scheme.   The DBAPI now works against
modern MySQL versions as well as MariaDB versions (in the latter case it's
required to pass charset/collation explicitly).   Note however that
server side cursor support is disabled due to unresolved issues with this
driver.

References: #12332
Change-Id: I81279478196e830d3c0d5f24ecb3fe2dc18d4ca6
2025-03-10 14:04:21 -04:00
Michael Bayer dfc3bf988b Merge "restate all upsert in terms of statement extensions (patch 3)" into main 2025-03-07 15:09:00 +00:00
Michael Bayer 127b12d857 Merge "Improve identity column reflection" into main 2025-03-07 14:20:45 +00:00
Federico Caselli b23b6db14a Improve identity column reflection
Add SQL typing to reflection query used to retrieve a the structure
of IDENTITY columns, adding explicit JSON typing to the query to suit
unusual PostgreSQL driver configurations that don't support JSON natively.

Fixed issue affecting PostgreSQL 17.3 and greater where reflection of
domains with "NOT NULL" as part of their definition would include an
invalid constraint entry in the data returned by
:meth:`_postgresql.PGInspector.get_domains` corresponding to an additional
"NOT NULL" constraint that isn't a CHECK constraint; the existing
``"nullable"`` entry in the dictionary already indicates if the domain
includes a "not null" constraint.   Note that such domains also cannot be
reflected on PostgreSQL 17.0 through 17.2 due to a bug on the PostgreSQL
side; if encountering errors in reflection of domains which include NOT
NULL, upgrade to PostgreSQL server 17.3 or greater.

Fixes: #11751
Change-Id: I8e69de51601dca3257186e38c6f699fbfd9014c6
2025-03-06 19:26:19 -05:00
Mike Bayer d5d4189ef6 restate all upsert in terms of statement extensions (patch 3)
Change-Id: I0595ba8e2bd930e22f4c06d7a813bcd23060cb7a
2025-03-06 18:28:18 +00:00
Mike Bayer 33be272290 implement mysql limit() for UPDATE/DELETE DML (patch 2)
Added new construct :func:`_mysql.limit` which can be applied to any
:func:`_sql.update` or :func:`_sql.delete` to provide the LIMIT keyword to
UPDATE and DELETE.  This new construct supersedes the use of the
"mysql_limit" dialect keyword argument.

Change-Id: Ie10c2f273432b0c8881a48f5b287f0566dde6ec3
2025-03-06 14:55:40 +00:00
KingOfKaste 48ad8c8111 Fix SQLite error for table with "WITHOUT ROWID" & "STRICT"
Fixed issue that omitted the comma between multiple SQLite table extension
clauses, currently ``WITHOUT ROWID`` and ``STRICT``, when both options
:paramref:`.Table.sqlite_with_rowid` and  :paramref:`.Table.sqlite_strict`
were configured at their non-default settings at the same time.  Pull
request courtesy david-fed.

Fixes: #12368
Closes: #12369
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12369
Pull-request-sha: 3c9ceffe82

Change-Id: I1a44fd2d655d0e6eaad8213a360879daca9e4f11
2025-02-20 15:24:11 -05:00
Federico Caselli 13677447a3 minor docs fixes
Change-Id: I7379bc6904daac711063734d2f43aa5f6e734a0f
2025-02-13 23:17:12 +01:00
Mike Bayer 79505b03b6 remove None exception in IN
Fixed SQL composition bug which impacted caching where using a ``None``
value inside of an ``in_()`` expression would bypass the usual "expanded
bind parameter" logic used by the IN construct, which allows proper caching
to take place.

Fixes: #12314
References: #12312
Change-Id: I0d2fc4e15c73407379ba368dd4ee32660fc66259
2025-02-05 14:08:51 -05:00
Mingyu Park 87bf36be84 Unable to use InstrumentedAttribute to value mappings in mysql/mariadb on_duplicate_key_update
Fixes: #12117
Closes: #12296
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12296
Pull-request-sha: 32a09ebd18

Change-Id: I72701f63b13105e5dc36e63ba2651da2673f1735
2025-02-01 19:15:47 +01:00
Mike Bayer 299cdf667d set default iso to None for asyncpg pep-249 wrapper
Adjusted the asyncpg connection wrapper so that the asyncpg
``.transaction()`` call sends ``None`` for isolation_level if not otherwise
set in the SQLAlchemy dialect/wrapper, thereby allowing asyncpg to make use
of the server level setting for isolation_level in the absense of a
client-level setting. Previously, this behavior of asyncpg was blocked by a
hardcoded ``read_committed``.

Fixes: #12159
Change-Id: I2cd878a5059a8fefc9557a9b8e056fedaee2e9a4
2025-01-20 13:12:19 -05:00
CommanderKeynes 7bfb829f25 Asyncpg null query fix
Adjusted the asyncpg dialect so that an empty SQL string, which is valid
for PostgreSQL server, may be successfully processed at the dialect level,
such as when using :meth:`.Connection.exec_driver_sql`. Pull request
courtesy Andrew Jackson.

Closes: #12220
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12220
Pull-request-sha: 45c94febee

Change-Id: I870df9e31f4a229939e76c702724c25073329282
2025-01-07 11:25:40 -05:00
Mike Bayer 6a87d619d9 fix SQLite on conflict tests
in I4d66ec1473321616a1707da324a7dfe7a61ec94e we added new tests
in the sqlite suite but we forgot to extend from fixtures.TestBase,
so these tests did not get run at all.  repair tests

Change-Id: Iaec17a754e0ab1d4b43f063706b512ed335a7465
2024-12-19 17:50:21 -05:00
Michael Bayer 7f16618fcf Merge "harden typing / coercion for on conflict/on duplicate key" into main 2024-12-18 20:43:25 +00:00
Mike Bayer 219bcb3a77 harden typing / coercion for on conflict/on duplicate key
in 2.1 we want these structures to be cacheable, so start
by cleaning up types and adding coercions to enforce those types.
these will be more locked down in 2.1 as we will need to move
bound parameter coercion outside of compilation, but here
do some small starts and introduce in 2.0.

in one interest of cachability, a "literal_binds" that found
its way into SQLite's compiler is replaced with "literal_execute",
the difference being that the latter is cacheable.   This literal
is apparently necessary to suit SQLite's query planner for
the "index criteria" portion of the on conflict clause that otherwise
can't work with a real bound parameter.

Change-Id: I4d66ec1473321616a1707da324a7dfe7a61ec94e
2024-12-18 14:23:51 -05:00
FeeeeK c5abd84a2c Add missing SmallInteger column spec for asyncpg
Adds missing column spec for `SmallInteger` in `asyncpg` driver

Fixes: #12170
Closes: #12171
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12171
Pull-request-sha: 82886d8521

Change-Id: I2cb15f066de756d4e3f21bcac6af2cf03bd25a1c
2024-12-17 20:27:22 +01:00
Michael Bayer 396c3fc70f Merge "SQLite strict tables" into main 2024-12-16 18:25:08 +00:00
Pablo Nicolas Estevez 134ad3bbdc add delete limit to mysql; ensure int for update/delete limits
Added support for the ``LIMIT`` clause with ``DELETE`` for the MySQL and
MariaDB dialects, to complement the already present option for
``UPDATE``. The :meth:`.delete.with_dialect_options` method of the
`:func:`.delete` construct accepts parameters for ``mysql_limit`` and
``mariadb_limit``, allowing users to specify a limit on the number of rows
deleted. Pull request courtesy of Pablo Nicolás Estevez.

Added logic to ensure that the ``mysql_limit`` and ``mariadb_limit``
parameters of :meth:`.update.with_dialect_options` and
:meth:`.delete.with_dialect_options` when compiled to string will only
compile if the parameter is passed as an integer; a ``ValueError`` is
raised otherwise.

corrected mysql documentation for update/delete options which
must be specified using the ``with_dialect_options()`` method.

Fixes: #11764
Closes: #12146
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12146
Pull-request-sha: e34708374c

Change-Id: I8681ddabaa192b672c7a9b9981c4fe9e4bdc8d03
2024-12-14 12:54:57 -05:00
Guilherme Martins Crocetti 5b0eeaca61 SQLite strict tables
Added SQLite table option to enable ``STRICT`` tables.

Fixes #7398
Closes: #12124
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12124
Pull-request-sha: e77273d0ba

Change-Id: I0ffe9f6fc2c27627f53a1bc1808077e74617658a
2024-12-12 21:55:46 +01:00
Mike Bayer 42fe1109c6 modernize PG domain reflection test and skip for pg17.2
Fixes: #12174
Change-Id: If4b1c29d7ee62b2858f1ef9d75fe1c4c41217706
2024-12-12 12:01:16 -05:00
Michael Bayer 860ca0b9d2 Merge "Separate Numeric and Float" into main 2024-12-09 21:47:48 +00:00
Mike Bayer 311e142ea6 Separate Numeric and Float
the :class:`.Numeric` and :class:`.Float` SQL types have been separated out
so that :class:`.Float` no longer inherits from :class:`.Numeric`; instead,
they both extend from a common mixin :class:`.NumericCommon`.  This
corrects for some architectural shortcomings where numeric and float types
are typically separate, and establishes more consistency with
:class:`.Integer` also being a distinct type.   The change should not have
any end-user implications except for code that may be using
``isinstance()`` to test for the :class:`.Numeric` datatype; third party
dialects which rely upon specific implementation types for numeric and/or
float may also require adjustment to maintain compatibility.

Fixes:  #5252
Change-Id: Iadc841340b3d97e3eb5f7e63f0a0cc3cb4e30f74
2024-12-09 14:29:26 -05:00
Michael Bayer c3097458d9 Merge "Added INET4 and INET6 types for MariaDB" into main 2024-11-21 12:36:33 +00:00
Adam Žurek 0f81c14b7c Added INET4 and INET6 types for MariaDB
Added sql types ``INET4`` and ``INET6`` in the MariaDB dialect.

Fixes: #10720
Closes: #12028
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12028
Pull-request-sha: 25f939076e

Change-Id: I2efa53420aa5566f61a19f228cb421116b2e2720
2024-11-19 08:59:25 -05:00
Michael Bayer 1b40521f5f Merge "apply quote to url.database portion" into main 2024-11-18 17:53:51 +00:00
Michael Bayer da886ba281 Merge "Support table function in oracle" into main 2024-11-18 17:53:20 +00:00
Frazer McLean 31975cfa38 Add Range.__contains__
<!-- Provide a general summary of your proposed changes in the Title field above -->

### Description
Fixes #12093

### 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:

- [ ] A documentation / typographical / small typing error fix
	- Good to go, no issue or tests are needed
- [x] 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: #12094
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12094
Pull-request-sha: 3f900e96b9

Change-Id: I4c3945eec6a931acd0a8c1682988c5f26e96a499
2024-11-15 19:10:24 +01:00
Federico Caselli 4c063e7df4 fix typo in test docs
Change-Id: I6d7b8b75b96c0096ea9de8e462895c006dcb8f7c
2024-11-15 18:57:54 +01:00
Mike Bayer feb17832f1 apply quote to url.database portion
Adjusted URL parsing and stringification to apply url quoting to the
"database" portion of the URL.  This allows a URL where the "database"
portion includes special characters such as question marks to be
accommodated.

Fixes: #11234
Change-Id: If868c96969b70f1090f0b474403d22fd3a2cc529
2024-11-15 08:11:40 -05:00