Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Hi,
I create an SQL table dataset inside my custom plugin recipe and try to delete just the dataset without dropping the table in the database. But the table is being dropped whether or not I set drop_data to True or False. Just wanted to check if I'm doing it the right way.
I referred to this documentation
Thanks
dataset = project.create_sql_table_dataset(table_name, "PostgreSQL", connection, table_name, schema)
dataset_settings = dataset.get_settings()
table_name_with_schema = '"' + schema + '"."' + table_name + '"'
dataset_settings.get_raw_params()["customPostWriteStatements"] = 'ALTER TABLE ' + table_name_with_schema + ' ADD COLUMN id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY; GRANT SELECT , DELETE ON TABLE ' + table_name_with_schema + ' TO psqladmin;'
dataset_settings.save()
src_dataset.copy_to(dataset, sync_schema=True, write_mode='OVERWRITE')
dataset.delete(drop_data=False)
Hi @jvijayakumar2 ,
As discussed on the support ticket your code does not wait for the copy_to to complete thus no table is created at that point.
You should avoid this by adding ( wait_for_result()
src_dataset.copy_to(dataset, sync_schema=True, write_mode='OVERWRITE').wait_for_result()
Thanks
The API reference says the drop_data=False but you have drop_na=False in your code.
It was drop_data=False that I was using. Corrected the sample snippet.
Hi @jvijayakumar2 ,
As discussed on the support ticket your code does not wait for the copy_to to complete thus no table is created at that point.
You should avoid this by adding ( wait_for_result()
src_dataset.copy_to(dataset, sync_schema=True, write_mode='OVERWRITE').wait_for_result()
Thanks
Thanks @AlexT I was able to get it working by adding wait_for_result()