def test_render_alias_in_array_sql(self): tb = Table("tb") q = PostgreSQLQuery.from_(tb).select( Array(tb.col).as_("different_name")) self.assertEqual(str(q), 'SELECT ARRAY["col"] "different_name" FROM "tb"')
def test_array_general(self): query = Query.from_(self.table_abc) \ .select(Array(1, 'a', ['b', 2, 3])) self.assertEqual('SELECT [1,\'a\',[\'b\',2,3]] FROM "abc"', str(query)) self.assertEqual('SELECT [1,\'a\',[\'b\',2,3]] FROM "abc"', str(query.get_sql()))
def test_array_postgresql(self): query = PostgreSQLQuery.from_(self.table_abc).select( Array(1, "a", ["b", 2, 3])) self.assertEqual("SELECT ARRAY[1,'a',ARRAY['b',2,3]] FROM \"abc\"", str(query)) self.assertEqual("SELECT ARRAY[1,'a',ARRAY['b',2,3]] FROM \"abc\"", query.get_sql())
def test_array_postgresql(self): query = PostgreSQLQuery.from_(self.table_abc) \ .select(Array(1, 'a', ['b', 2, 3])) self.assertEqual('SELECT ARRAY[1,\'a\',ARRAY[\'b\',2,3]] FROM "abc"', str(query)) self.assertEqual('SELECT ARRAY[1,\'a\',ARRAY[\'b\',2,3]] FROM "abc"', query.get_sql())
def test_array_syntax(self): tb = Table("tb") q = PostgreSQLQuery.from_(tb).select(Array(1, "a", ["b", 2, 3])) self.assertEqual(str(q), "SELECT ARRAY[1,'a',ARRAY['b',2,3]] FROM \"tb\"")
def test_array_general(self): query = Query.from_(self.table_abc).select(Array(1, "a", ["b", 2, 3])) self.assertEqual("SELECT [1,'a',['b',2,3]] FROM \"abc\"", str(query))
def test_psql_array_general(self): query = PostgreSQLQuery.from_(self.table_abc).select( Array(1, Array(2, 2, 2), 3)) self.assertEqual('SELECT ARRAY[1,ARRAY[2,2,2],3] FROM "abc"', str(query))
def test_empty_psql_array(self): query = PostgreSQLQuery.from_(self.table_abc).select(Array()) self.assertEqual("SELECT '{}' FROM \"abc\"", str(query))