0

I have been struggling with an odbc connection and seemingly limited to being able to pass .sql query files that are on a single line.

e.g. If I pass a .sql file with the following content, things work great:

select * from `ourproject.ua.sometable` limit 10;

However, if the file looks like this:

SELECT * 
FROM `ourproject.ua.sometable` 
LIMIT 10;

I get errors.

My command looks like this, where the queries above are in the file query.sql:

isql -v -b BigQuery < query.sql > data.txt

I wondered if there's a bash command work around solution where I could tell bash to read query.sql as a single line, or 'reduce' the file to a single line, before passing to isql.

Is this possible?

[edit] I tried some solutions from over here but these seem to interpret the contents of the file as a command, whereas I need an intermediate step of getting them into one line before passing them to a command e.g.

echo `cat query.sql`
SELECT SimbaODBCDriverforGoogleBigQuery_2.4.6.1015-Linux.tar.gz bin bla.txt boot data.txt dev etc home lib lib64 media mnt opt proc query.sql root run sbin service.json srv sys tmp usr var FROM `ga4-extract.analytics_302644320.events_20220608` LIMIT 10;

Expected/wanted just a single line:

select * FROM `ga4-extract.analytics_302644320.events_20220608` LIMIT 10;
Doug Fir
  • 19,971
  • 47
  • 169
  • 299
  • Are you sure that's the problem? `tr '\012' ' ' data.txt` – tripleee Jul 14 '22 at 10:33
  • Thanks for the suggestion @tripleee this gave me `tr -d '\012' query.sql | isql -v -b BQODBC > data.txt tr: extra operand 'query.sql' Only one string may be given when deleting without squeezing repeats. Try 'tr --help' for more information. ` – Doug Fir Jul 14 '22 at 10:40
  • 1
    You missed the `<` – tripleee Jul 14 '22 at 10:46
  • 1
    The `echo` without quotes is just [broken quoting](https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable) – tripleee Jul 14 '22 at 10:47
  • Bam! It works! (with `tr`) I'm reading your link on broken quoting... is it possible to use cat in that way somehow? See my edit for example – Doug Fir Jul 14 '22 at 10:49
  • Seems like a really roundabout way to accomplish what you want. – tripleee Jul 14 '22 at 10:52
  • I liked the readability of using `cat`. E.g. this still returns a multi line output `echo "`cat query.sql`"` – Doug Fir Jul 14 '22 at 10:54
  • I'm afraid Ask Ubuntu solutions tend to be unsophisticated if not outright broken. – tripleee Jul 14 '22 at 10:56
  • I'll still with `tr` and do some reading, thanks very much for your help here – Doug Fir Jul 14 '22 at 10:57

0 Answers0