Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQL Columns Remover

Is simple script able to remove unused columns and replace him on datas from sql files, you need to give a columns name from insert

How to use

To use it, you need to open terminal and enter python command with multiple args:

  • {entry_file} (must inside script directory)
  • {output_file} (generate in directory of script)
  • {table_name} tale name in sql file
  • {columns} to remove (like column1,column2,column3)
python3 sql_column_remover.py entry_file.sql output_file.sql table_name column1,column2

Example

Imagine you have a file named entries.sql with this structure :

INSERT INTO `ps_product` (`id_product`, `id_supplier`, `id_manufacturer`, `id_category_default`, `id_shop_default`, `id_tax_rules_group`, `on_sale`, `online_only`, `ean13`, `isbn`, `upc`, `mpn`, `ecotax`, `quantity`, `minimal_quantity`, `low_stock_threshold`, `low_stock_alert`, `price`, `wholesale_price`, `unity`, `unit_price`, `unit_price_ratio`, `additional_shipping_cost`, `reference`, `supplier_reference`, `location`, `width`, `height`, `depth`, `weight`, `out_of_stock`, `additional_delivery_times`, `quantity_discount`, `customizable`, `uploadable_files`, `text_fields`, `active`, `redirect_type`, `id_type_redirected`, `available_for_order`, `available_date`, `show_condition`, `condition`, `show_price`, `indexed`, `visibility`, `cache_is_pack`, `cache_has_attachments`, `is_virtual`, `cache_default_attribute`, `date_add`, `date_upd`, `advanced_stock_management`, `pack_stock_type`, `state`, `product_type`) VALUES
(21, 0, 0, 15, 1, 1, 0, 0, '3701650300423', '', '', '', 0.000000, 0, 1, NULL, 0, 1.624000, 0.000000, 'prix au mètre', 0.000000, 0.000000, 0.000000, '', '', '', 200.000000, 50.000000, 110.000000, 4.850000, 2, 1, 0, 0, 0, 0, 1, '404', 0, 1, '0000-00-00', 0, 'new', 1, 1, 'both', 0, 0, 0, 50, '2023-04-03 15:01:26', '2024-09-06 08:13:45', 0, 3, 1, 'combinations'),
(22, 0, 0, 15, 1, 1, 0, 0, '3701650300386', '', '', '', 0.000000, 0, 1, 0, 0, 1.914000, 0.000000, 'Prix au mètre', 0.000000, 0.000000, 0.000000, '', '', '', 200.000000, 50.000000, 11.000000, 4.350000, 2, 1, 0, 0, 0, 0, 1, 'default', 0, 1, '0000-00-00', 0, 'new', 1, 1, 'both', 0, 0, 0, 66, '2023-04-03 15:26:56', '2025-03-04 15:25:22', 0, 3, 1, 'combinations'),
(24, 0, 0, 15, 1, 1, 0, 0, '3701650300348', '', '', '', 0.000000, 0, 1, NULL, 0, 2.842000, 0.000000, 'Prix au mètre', 0.000000, 0.000000, 0.000000, '', '', '', 200.000000, 90.000000, 21.000000, 12.750000, 2, 1, 0, 0, 0, 0, 1, '404', 0, 1, '0000-00-00', 0, 'new', 1, 1, 'both', 0, 0, 0, 70, '2023-04-04 09:10:19', '2024-09-06 08:14:46', 0, 3, 1, 'combinations'),
(25, 0, 0, 15, 1, 1, 0, 0, '3701650300461', '', '', '', 0.000000, 0, 1, NULL, 0, 3.480000, 0.000000, 'Prix au mètre', 0.000000, 0.000000, 0.000000, '', '', '', 0.000000, 0.000000, 0.000000, 0.000000, 2, 1, 0, 0, 0, 0, 1, '404', 0, 1, '0000-00-00', 0, 'new', 1, 1, 'both', 0, 0, 0, 74, '2023-04-04 09:23:38', '2024-09-06 08:13:12', 0, 3, 1, 'combinations');

And you would like to remove column ecotax and upc. For that you need to run this command :

python3 sql_column_remover.py entries.sql output.sql ps_product ecotax,upc

You will get messages when is finish, like :

Tentative de traitement alternatif...
Traitement alternatif terminé. La requête modifiée a été sauvegardée dans 'output.sql'.

And if you check output.sql you will show the difference

INSERT INTO `ps_product` (`id_product`, `id_supplier`, `id_manufacturer`, `id_category_default`, `id_shop_default`, `id_tax_rules_group`, `on_sale`, `online_only`, `ean13`, `isbn`, `mpn`, `quantity`, `minimal_quantity`, `low_stock_threshold`, `low_stock_alert`, `price`, `wholesale_price`, `unity`, `unit_price`, `unit_price_ratio`, `additional_shipping_cost`, `reference`, `supplier_reference`, `location`, `width`, `height`, `depth`, `weight`, `out_of_stock`, `additional_delivery_times`, `quantity_discount`, `customizable`, `uploadable_files`, `text_fields`, `active`, `redirect_type`, `id_type_redirected`, `available_for_order`, `available_date`, `show_condition`, `condition`, `show_price`, `indexed`, `visibility`, `cache_is_pack`, `cache_has_attachments`, `is_virtual`, `cache_default_attribute`, `date_add`, `date_upd`, `advanced_stock_management`, `pack_stock_type`, `state`, `product_type`) VALUES
(21, 0, 0, 15, 1, 1, 0, 0, '3701650300423', '', '', 0, 1, NULL, 0, 1.624000, 0.000000, 'prix au mètre', 0.000000, 0.000000, 0.000000, '', '', '', 200.000000, 50.000000, 110.000000, 4.850000, 2, 1, 0, 0, 0, 0, 1, '404', 0, 1, '0000-00-00', 0, 'new', 1, 1, 'both', 0, 0, 0, 50, '2023-04-03 15:01:26', '2024-09-06 08:13:45', 0, 3, 1, 'combinations'),
(22, 0, 0, 15, 1, 1, 0, 0, '3701650300386', '', '', 0, 1, 0, 0, 1.914000, 0.000000, 'Prix au mètre', 0.000000, 0.000000, 0.000000, '', '', '', 200.000000, 50.000000, 11.000000, 4.350000, 2, 1, 0, 0, 0, 0, 1, 'default', 0, 1, '0000-00-00', 0, 'new', 1, 1, 'both', 0, 0, 0, 66, '2023-04-03 15:26:56', '2025-03-04 15:25:22', 0, 3, 1, 'combinations'),
(24, 0, 0, 15, 1, 1, 0, 0, '3701650300348', '', '', 0, 1, NULL, 0, 2.842000, 0.000000, 'Prix au mètre', 0.000000, 0.000000, 0.000000, '', '', '', 200.000000, 90.000000, 21.000000, 12.750000, 2, 1, 0, 0, 0, 0, 1, '404', 0, 1, '0000-00-00', 0, 'new', 1, 1, 'both', 0, 0, 0, 70, '2023-04-04 09:10:19', '2024-09-06 08:14:46', 0, 3, 1, 'combinations'),
(25, 0, 0, 15, 1, 1, 0, 0, '3701650300461', '', '', 0, 1, NULL, 0, 3.480000, 0.000000, 'Prix au mètre', 0.000000, 0.000000, 0.000000, '', '', '', 0.000000, 0.000000, 0.000000, 0.000000, 2, 1, 0, 0, 0, 0, 1, '404', 0, 1, '0000-00-00', 0, 'new', 1, 1, 'both', 0, 0, 0, 74, '2023-04-04 09:23:38', '2024-09-06 08:13:12', 0, 3, 1, 'combinations');

About

Python Script to remove unused column from sql script

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages