Imagine this scenario: you are given an Excel/LibreOffice spreadsheet (but increasingly now collaborating on a Google Sheet) where some columns are already filled, particularly a column containing row ID or primary key of some sort (e.g. client_id). Then, you have some other columns that you fill manually (e.g. audit_note). Finally, you also have yet some other columns that you need to fill from database (e.g. client_email, client_phone) so this sheet can be given to the sales person to follow up.
Currently my solution to fill the columns is the mysql-fill-csv-columns-from-query script. The flow is:
1. I select all cells on the Google Sheet, paste to terminal or a text file and save it to tmp1.tsv, then run something like:
% mysql-fill-csv-columns-from-query DBNAME --tsv tmp1.tsv 'SELECT c.email AS client_email, c.phone AS client_phone FROM clients c ... WHERE c.id=$client_id' > tmp2.csv
The script basically takes the SQL, replaces $xxx parts with value of corresponding CSV field, runs the query, fetches a single row, then adds/sets CSV fields from the SQL SELECT fields. It does this for every CSV row.
2. I then open tmp2.csv using LibreOffice then copy-paste the columns to the Google Sheet.
It is very much still bearable, but I am wondering whether there is an easier flow, preferably where Perl is still involved somehow.
In reply to Filling spreadsheet columns with data from database by perlancar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |