4 ms·
> Switching from wide to long is a simple operation, commonly called a "melt". Unfortunately, it's not available in SQL. That's not completely true. In most SQ
by mrighele 3y ago
> Switching from wide to long is a simple operation, commonly called a "melt". Unfortunately, it's not available in SQL.
That's not completely true. In most SQL databases you can query information about the table, and this is true for Sqlite too. You cannot use this information to have a query with a "dynamic" number of columns, but you can always generate the query from the metadata and then executed the generated queries. It is not exactly fun to do as a one-liner, but it works:
> curl 'https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.csv https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.csv' | sqlite3 -csv ':memory:' '.import /dev/stdin stdin' '.mode list' '.output query.sql' "select 'select Date, ''' || name || ''', ' || name || ' from stdin ;' from pragma_table_info('stdin') where cid > 0 and cid < 42;" '.output stdout' '.mode csv' '.read query.sql'
(yes, you're also left with some temporary file on the computer).