google-bigquerydml

Is it possible to escape a column with a duplicate name to a function in BigQuery in DML


What's the problem

I'm trying to use DML where one of the columns being worked with has the same name as an internal BigQuery function, in this case hash.

Attempting to use column in any DML returns:

Syntax error: Unexpected keyword HASH at [line]
INSERT INTO
    dataset.table (_PARTITIONTIME,
    protocol,
    domain,
    path,
    query,
    hash
    ...

Is it possible to somehow tell BigQuery to ignore the formula and treat it as a string?

Larger scenario

I've come across this table and need to migrate the column type of other columns in the table from FLOAT to INT.

Everything else, the partitions etc. (including the column hash) should ideally be preserved.

Typically I would do this with DML, but because of the hash problem above I can't do that with insert. I got around re-creating the table using bq cli, but can't figure out how to do it with insert.

There's a lot of legacy here, do I need to convince people to rename the column or can I just nicely work around this.


Solution

  • Answer via Jaytiger in the comments.

    Wrapping it in backticks solved the problem i.e.:

    INSERT INTO
        dataset.table (_PARTITIONTIME,
        protocol,
        domain,
        path,
        query,
        `hash`
        ...