MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / quoted_name

Class quoted_name

lib/sqlalchemy/sql/elements.py:5242–5340  ·  view source on GitHub ↗

Represent a SQL identifier combined with quoting preferences. :class:`.quoted_name` is a Python unicode/str subclass which represents a particular identifier name along with a ``quote`` flag. This ``quote`` flag, when set to ``True`` or ``False``, overrides automatic quoting behavi

Source from the content-addressed store, hash-verified

5240
5241
5242class quoted_name(util.MemoizedSlots, str):
5243 """Represent a SQL identifier combined with quoting preferences.
5244
5245 :class:`.quoted_name` is a Python unicode/str subclass which
5246 represents a particular identifier name along with a
5247 ``quote`` flag. This ``quote`` flag, when set to
5248 ``True`` or ``False``, overrides automatic quoting behavior
5249 for this identifier in order to either unconditionally quote
5250 or to not quote the name. If left at its default of ``None``,
5251 quoting behavior is applied to the identifier on a per-backend basis
5252 based on an examination of the token itself.
5253
5254 A :class:`.quoted_name` object with ``quote=True`` is also
5255 prevented from being modified in the case of a so-called
5256 "name normalize" option. Certain database backends, such as
5257 Oracle Database, Firebird, and DB2 "normalize" case-insensitive names
5258 as uppercase. The SQLAlchemy dialects for these backends
5259 convert from SQLAlchemy's lower-case-means-insensitive convention
5260 to the upper-case-means-insensitive conventions of those backends.
5261 The ``quote=True`` flag here will prevent this conversion from occurring
5262 to support an identifier that's quoted as all lower case against
5263 such a backend.
5264
5265 The :class:`.quoted_name` object is normally created automatically
5266 when specifying the name for key schema constructs such as
5267 :class:`_schema.Table`, :class:`_schema.Column`, and others.
5268 The class can also be
5269 passed explicitly as the name to any function that receives a name which
5270 can be quoted, such as :meth:`.Inspector.has_table` with an
5271 unconditionally quoted name::
5272
5273 from sqlalchemy import create_engine
5274 from sqlalchemy import inspect
5275 from sqlalchemy.sql import quoted_name
5276
5277 engine = create_engine("oracle+oracledb://some_dsn")
5278 print(inspect(engine).has_table(quoted_name("some_table", True)))
5279
5280 The above logic will run the "has table" logic against the Oracle Database
5281 backend, passing the name exactly as ``"some_table"`` without converting to
5282 upper case.
5283
5284 A :class:`.quoted_name` object with ``quote=False`` may be passed to APIs
5285 that apply automatic quoting in order to keep the given name unquoted,
5286 such as when a PostgreSQL ``INHERITS`` option refers to a schema-qualified
5287 table name like ``my_schema.some_table``.
5288
5289 .. versionchanged:: 1.2 The :class:`.quoted_name` construct is now
5290 importable from ``sqlalchemy.sql``, in addition to the previous
5291 location of ``sqlalchemy.sql.elements``.
5292
5293 """
5294
5295 __slots__ = "quote", "lower", "upper"
5296
5297 quote: Optional[bool]
5298
5299 @overload

Calls

no outgoing calls