Skip to content

Commit

Permalink
Update check for table existence to be case insensitive (#2086)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlstadther authored and Tarrasch committed Jun 24, 2017
1 parent 61ee32e commit 8874b93
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions luigi/contrib/redshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,11 @@ def does_table_exist(self, connection):
if '.' in self.table:
query = ("select 1 as table_exists "
"from information_schema.tables "
"where table_schema = %s and table_name = %s limit 1")
"where table_schema = lower(%s) and table_name = lower(%s) limit 1")
else:
query = ("select 1 as table_exists "
"from pg_table_def "
"where tablename = %s limit 1")
"where tablename = lower(%s) limit 1")
cursor = connection.cursor()
try:
cursor.execute(query, tuple(self.table.split('.')))
Expand Down
8 changes: 4 additions & 4 deletions test/contrib/redshift_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_s3_copy_to_table(self, mock_redshift_target, mock_copy):
# Check the SQL query in `S3CopyToTable.does_table_exist`.
mock_cursor.execute.assert_called_with("select 1 as table_exists "
"from pg_table_def "
"where tablename = %s limit 1",
"where tablename = lower(%s) limit 1",
(task.table,))

return
Expand Down Expand Up @@ -188,7 +188,7 @@ def test_s3_copy_to_temp_table(self, mock_redshift_target, mock_copy):
mock_cursor.execute.assert_any_call(
"select 1 as table_exists "
"from pg_table_def "
"where tablename = %s limit 1",
"where tablename = lower(%s) limit 1",
(task.table,),
)

Expand All @@ -212,8 +212,8 @@ def test_s3_copy_to_table(self, mock_redshift_target, mock_copy):
mock_cursor.execute.assert_called_with(
"select 1 as table_exists "
"from information_schema.tables "
"where table_schema = %s and "
"table_name = %s limit 1",
"where table_schema = lower(%s) and "
"table_name = lower(%s) limit 1",
tuple(task.table.split('.')),
)

Expand Down

0 comments on commit 8874b93

Please sign in to comment.