question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Syntax Error on nested queries from google spreadsheet with blank column names

See original GitHub issue

Redash 4.0.1+b4038 Pulling data from google spreadsheet the spreadsheet has some columns with blank headers If I run a query against the query results from pulling in the spreadsheet (e.g. query_45) I get an error

File "/opt/redash/redash.4.0.1.b4038/redash/query_runner/query_results.py", line 92, in create_table
    connection.execute(create_table)
OperationalError: near ")": syntax error

This is caused by create_table with a create table string that contains a blank column header at the end. e.g.

CREATE TABLE table_46 (Name, Phone, )

I hacked a fix into my query_results.py to create named columns for blank columns.

------------------query_results.py:79--------------------

def fix_column_name(name,columncounter):
    if name.strip() == '':
        name = u"BLANK{colno}".format(colno=columncounter)

    return name.replace(':', '_').replace('.', '_').replace(' ', '_')


def create_table(connection, table_name, query_results):
    columns = [column['name']
               for column in query_results['columns']]
    safe_columns = []
    colno = 0
    for column in columns:
        safe_columns.append(fix_column_name(column,colno))
        colno = colno + 1 

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
metheoscommented, Jul 2, 2018

I would suggest Excel style with letters since that’s what excel and google docs both use for the column id. It would make it easier for someone to refer back to their spreadsheet if it’s a complex one.

1reaction
arikfrcommented, Jul 2, 2018

Let’s go with option #2 - rename the columns. But instead of blank_, maybe column_ + column number?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Formula Parse Errors In Google Sheets And How To Fix Them
In this post, I'll explain what a Google Sheets formula parse error is, how to identify what's causing the problem, and how to...
Read more >
Query Function in Google Sheets - Complete Tutorial
Learn how lazy Google Sheets users take advantage of the QUERY function, which lets you write SQL queries in a Sheet. Sit back...
Read more >
syntax error SELECT list cannot be empty at [1:9]. Halp? - Reddit
The first SELECT is missing a select list, so you'll have to add a column to select there or * to select all...
Read more >
How to use Google Sheets QUERY function - Ablebits
headers is optional for when you need to indicate the number of header rows in your data. Omit the argument (as I do...
Read more >
5+ Easy Fixes for the Formula Parse Error in Google Sheets
This type of error is unique to Google Sheets. It usually occurs when Google Sheets cannot make sense of your formula, so it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found