diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b3c37979e0..dbf7b611d37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,8 @@ - [Add `Text.to_decimal`.][10874] - [Added .floor, .ceil, .trunc to the in-memory `Decimal` column.][10887] - [Added vectorized .round to the in-memory `Decimal` column.][10912] +- [`select_into_database_table` no longer defaults the primary key to the first + column][11120] [10614]: https://github.com/enso-org/enso/pull/10614 [10660]: https://github.com/enso-org/enso/pull/10660 @@ -71,6 +73,7 @@ [10874]: https://github.com/enso-org/enso/pull/10874 [10887]: https://github.com/enso-org/enso/pull/10887 [10912]: https://github.com/enso-org/enso/pull/10912 +[11120]: https://github.com/enso-org/enso/pull/11120 #### Enso Language & Runtime diff --git a/distribution/lib/Standard/Database/0.0.0-dev/src/Extensions/Upload_Database_Table.enso b/distribution/lib/Standard/Database/0.0.0-dev/src/Extensions/Upload_Database_Table.enso index 6bd68b7de13..1835d0dba57 100644 --- a/distribution/lib/Standard/Database/0.0.0-dev/src/Extensions/Upload_Database_Table.enso +++ b/distribution/lib/Standard/Database/0.0.0-dev/src/Extensions/Upload_Database_Table.enso @@ -60,7 +60,7 @@ from project.Internal.Upload.Operations.Update import common_update_table rows, so errors may still occur when the output action is enabled. @primary_key Widget_Helpers.make_column_name_vector_selector DB_Table.select_into_database_table : Connection -> Text -> Vector Text | Nothing -> Boolean -> Problem_Behavior -> DB_Table ! Table_Already_Exists | Inexact_Type_Coercion | Missing_Input_Columns | Non_Unique_Key | SQL_Error | Illegal_Argument -DB_Table.select_into_database_table self connection (table_name : Text) primary_key=[self.columns.first.name] temporary=False on_problems:Problem_Behavior=..Report_Warning = +DB_Table.select_into_database_table self connection (table_name : Text) primary_key=[] temporary=False on_problems:Problem_Behavior=..Report_Warning = select_into_table_implementation self connection table_name primary_key temporary on_problems ## GROUP Standard.Base.Output diff --git a/distribution/lib/Standard/Database/0.0.0-dev/src/Extensions/Upload_In_Memory_Table.enso b/distribution/lib/Standard/Database/0.0.0-dev/src/Extensions/Upload_In_Memory_Table.enso index 235767832d6..5c159cd8f06 100644 --- a/distribution/lib/Standard/Database/0.0.0-dev/src/Extensions/Upload_In_Memory_Table.enso +++ b/distribution/lib/Standard/Database/0.0.0-dev/src/Extensions/Upload_In_Memory_Table.enso @@ -57,7 +57,7 @@ from project.Internal.Upload.Operations.Select_Into import select_into_table_imp rows, so errors may still occur when the output action is enabled. @primary_key Widget_Helpers.make_column_name_vector_selector Table.select_into_database_table : Connection -> Text -> Vector Text | Nothing -> Boolean -> Problem_Behavior -> DB_Table ! Table_Already_Exists | Inexact_Type_Coercion | Missing_Input_Columns | Non_Unique_Key | SQL_Error | Illegal_Argument -Table.select_into_database_table self connection (table_name : Text) primary_key=[self.columns.first.name] temporary=False on_problems:Problem_Behavior=..Report_Warning = +Table.select_into_database_table self connection (table_name : Text) primary_key=[] temporary=False on_problems:Problem_Behavior=..Report_Warning = select_into_table_implementation self connection table_name primary_key temporary on_problems ## GROUP Standard.Base.Output diff --git a/test/Table_Tests/src/Database/Upload_Spec.enso b/test/Table_Tests/src/Database/Upload_Spec.enso index 8cbd010ac29..1f2f3b348ac 100644 --- a/test/Table_Tests/src/Database/Upload_Spec.enso +++ b/test/Table_Tests/src/Database/Upload_Spec.enso @@ -358,13 +358,18 @@ add_specs suite_builder setup make_new_connection persistent_connector=True = db_table_2 = t1.select_into_database_table data.connection (Name_Generator.random_name "primary-key-2") Panic.with_finalizer (data.connection.drop_table db_table_2.name) <| db_table_2.at "X" . to_vector . should_equal_ignoring_order [1, 2, 3] - db_table_2.get_primary_key . should_equal ["X"] + db_table_2.get_primary_key . should_equal Nothing db_table_3 = t1.select_into_database_table data.connection (Name_Generator.random_name "primary-key-3") primary_key=Nothing Panic.with_finalizer (data.connection.drop_table db_table_3.name) <| db_table_3.at "X" . to_vector . should_equal_ignoring_order [1, 2, 3] db_table_3.get_primary_key . should_equal Nothing + db_table_4 = t1.select_into_database_table data.connection (Name_Generator.random_name "primary-key-4") + Panic.with_finalizer (data.connection.drop_table db_table_4.name) <| + db_table_4.at "X" . to_vector . should_equal_ignoring_order [1, 2, 3] + db_table_4.get_primary_key . should_equal Nothing + group_builder.specify "should ensure that primary key columns are valid" <| run_with_and_without_output <| r1 = data.in_memory_table.select_into_database_table data.connection (Name_Generator.random_name "primary-key-4") primary_key=["X", "nonexistent"] @@ -381,7 +386,7 @@ add_specs suite_builder setup make_new_connection persistent_connector=True = group_builder.specify "should fail if the primary key contains nulls" <| t1 = Table.new [['X', [1, Nothing, 3]], ['Y', [4, 5, Nothing]]] run_with_and_without_output <| - r1 = t1.select_into_database_table data.connection (Name_Generator.random_name "primary-key-null-0") temporary=True primary_key=[] + r1 = t1.select_into_database_table data.connection (Name_Generator.random_name "primary-key-null-0") temporary=True r1.row_count . should_equal 3 r2 = t1.select_into_database_table data.connection (Name_Generator.random_name "primary-key-null-1") temporary=True primary_key=['X'] @@ -564,7 +569,7 @@ add_specs suite_builder setup make_new_connection persistent_connector=True = if data.connection.dialect.dialect_flags.primary_key.allows_nulls then group_builder.specify "should fail when the primary key contains nulls" <| t = Table.new [['X', [1, Nothing, 3]], ['Y', [4, 5, Nothing]]] - db_table = t.select_into_database_table data.connection (Name_Generator.random_name "source-table-nulls-1") temporary=True primary_key=Nothing + db_table = t.select_into_database_table data.connection (Name_Generator.random_name "source-table-nulls-1") temporary=True Problems.assume_no_problems db_table run_with_and_without_output <| @@ -574,11 +579,11 @@ add_specs suite_builder setup make_new_connection persistent_connector=True = if data.connection.dialect.dialect_flags.primary_key.allows_nulls.not then group_builder.specify "should fail when the primary key contains nulls" <| t = Table.new [['X', [1, Nothing, 3]], ['Y', [4, 5, Nothing]]] - db_table = t.select_into_database_table data.connection (Name_Generator.random_name "source-table-nulls-1") temporary=True primary_key=Nothing + db_table = t.select_into_database_table data.connection (Name_Generator.random_name "source-table-nulls-1") temporary=True Problems.assume_no_problems db_table run_with_and_without_output <| - r1 = db_table.select_into_database_table data.connection (Name_Generator.random_name "primary-key-null-1") temporary=True primary_key=[] + r1 = db_table.select_into_database_table data.connection (Name_Generator.random_name "primary-key-null-1") temporary=True r1.row_count . should_equal 3 r2 = db_table.select_into_database_table data.connection (Name_Generator.random_name "primary-key-null-2") temporary=True primary_key=['X']