summaryrefslogtreecommitdiff
path: root/test/dialect/postgresql/test_compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-11-22 10:59:06 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2021-11-22 11:26:33 -0500
commitd3a4e96196cd47858de072ae589c6554088edc24 (patch)
tree7ef233ee6f106e1e70a1aed5166f09f4d5960196 /test/dialect/postgresql/test_compiler.py
parent0b95f0055be252b13e99b0a944466f60b5e367ff (diff)
downloadsqlalchemy-d3a4e96196cd47858de072ae589c6554088edc24.tar.gz
Support lightweight compiler column elements w/ slots
the _CompileLabel class included ``__slots__`` but these weren't used as the superclasses included slots. Create a ``__slots__`` superclass for ``ClauseElement``, creating a new class of compilable SQL elements that don't include heavier features like caching, annotations and cloning, which are meant to be used only in an ad-hoc compiler fashion. Create new ``CompilerColumnElement`` from that which serves in column-oriented contexts, but similarly does not include any expression operator support as it is intended to be used only to generate a string. Apply this to both ``_CompileLabel`` as well as PostgreSQL ``_ColonCast``, which does not actually subclass ``ColumnElement`` as this class has memoized attributes that aren't worth changing, and does not include SQL operator capabilities as these are not needed for these compiler-only objects. this allows us to more inexpensively add new ad-hoc labels / casts etc. at compile time, as we will be seeking to expand out the typecasts that are needed for PostgreSQL dialects in a subsequent patch. Change-Id: I52973ae3295cb6e2eb0d7adc816c678a626643ed
Diffstat (limited to 'test/dialect/postgresql/test_compiler.py')
-rw-r--r--test/dialect/postgresql/test_compiler.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py
index 93513c39d..7e91f0ebb 100644
--- a/test/dialect/postgresql/test_compiler.py
+++ b/test/dialect/postgresql/test_compiler.py
@@ -38,6 +38,7 @@ from sqlalchemy.dialects.postgresql import array_agg as pg_array_agg
from sqlalchemy.dialects.postgresql import ExcludeConstraint
from sqlalchemy.dialects.postgresql import insert
from sqlalchemy.dialects.postgresql import TSRANGE
+from sqlalchemy.dialects.postgresql.base import _ColonCast
from sqlalchemy.dialects.postgresql.base import PGDialect
from sqlalchemy.dialects.postgresql.psycopg2 import PGDialect_psycopg2
from sqlalchemy.orm import aliased
@@ -98,6 +99,14 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
__dialect__ = postgresql.dialect()
+ def test_colon_cast_is_slots(self):
+
+ c1 = _ColonCast(column("q"), String(50))
+
+ assert not hasattr(c1, "__dict__")
+
+ self.assert_compile(c1, "q::VARCHAR(50)")
+
def test_update_returning(self):
dialect = postgresql.dialect()
table1 = table(