--- /dev/null
+.. change::
+ :tags: bug, sql, postgresql
+ :tickets: 6183
+
+ Fixed bug in new :meth:`_functions.FunctionElement.render_derived` feature
+ where column names rendered out explicitly in the alias SQL would not have
+ proper quoting applied for case sensitive names and other non-alphanumeric
+ names.
from sqlalchemy import and_
from sqlalchemy import cast
from sqlalchemy import Column
+from sqlalchemy import column
from sqlalchemy import Date
from sqlalchemy import DateTime
from sqlalchemy import exc
connection.execute(stmt).all(),
[(14, 1), (41, 2), (7, 3), (54, 4), (9, 5), (49, 6)],
)
+
+ @testing.only_on(
+ "postgresql+psycopg2",
+ "I cannot get this to run at all on other drivers, "
+ "even selecting from a table",
+ )
+ def test_render_derived_quoting(self, connection):
+ fn = (
+ func.json_to_recordset( # noqa
+ '[{"CaseSensitive":1,"the % value":"foo"}, '
+ '{"CaseSensitive":"2","the % value":"bar"}]'
+ )
+ .table_valued(
+ column("CaseSensitive", Integer), column("the % value", String)
+ )
+ .render_derived(with_types=True)
+ )
+
+ stmt = select(fn.c.CaseSensitive, fn.c["the % value"])
+
+ eq_(connection.execute(stmt).all(), [(1, "foo"), (2, "bar")])
"AS anon_1(a INTEGER, b VARCHAR)",
)
+ def test_named_table_valued_w_quoting(self):
+
+ fn = (
+ func.json_to_recordset( # noqa
+ '[{"CaseSensitive":1,"the % value":"foo"}, '
+ '{"CaseSensitive":"2","the % value":"bar"}]'
+ )
+ .table_valued(
+ column("CaseSensitive", Integer), column("the % value", String)
+ )
+ .render_derived(with_types=True)
+ )
+
+ stmt = select(fn.c.CaseSensitive, fn.c["the % value"])
+
+ self.assert_compile(
+ stmt,
+ 'SELECT anon_1."CaseSensitive", anon_1."the % value" '
+ "FROM json_to_recordset(:json_to_recordset_1) "
+ 'AS anon_1("CaseSensitive" INTEGER, "the % value" VARCHAR)',
+ )
+
def test_named_table_valued_subquery(self):
fn = (