except KeyError:
type_name = ti.regtype.encode(tx.encoding)
self._names_cache[ti.regtype, tx.encoding] = type_name
+ if dumper.oid == ti.array_oid:
+ type_name += b"[]"
rv = b"%s::%s" % (rv, type_name)
return rv
with pytest.raises(ProgrammingError):
sql.Literal(Foo()).as_string(conn)
+ def test_array(self, conn):
+ assert (
+ sql.Literal([dt.date(2000, 1, 1)]).as_string(conn)
+ == "'{2000-01-01}'::date[]"
+ )
+
@pytest.mark.parametrize("name", ["a-b", f"{eur}", "order"])
def test_invalid_name(self, conn, name):
conn.execute(
cur = conn.execute(sql.SQL("select {}").format("hello"))
assert cur.fetchone()[0] == "hello-inv"
+ assert (
+ sql.Literal(["hello"]).as_string(conn) == f"'{{hello-inv}}'::\"{name}\"[]"
+ )
+ cur = conn.execute(sql.SQL("select {}").format(["hello"]))
+ assert cur.fetchone()[0] == ["hello-inv"]
+
class TestSQL:
def test_class(self):