Home > Enterprise >  SNOWFLAKE querying column name with Spaces
SNOWFLAKE querying column name with Spaces

Time:01-31

I am trying to use agg functions to query data, I have space in the column name in SNOWFLAKE

select item, avg(item price) from order group by item;

The error is

Numerical value '1212.11' is not recognized

Expected output is

Code which gives item and avg price of that item

CodePudding user response:

Try

select item, try_to_number(avg("item price")) from order group by item;

CodePudding user response:

If you try add " (double quotes) around the column name does that help?

select item, avg("item price"::INT) from order group by item;

The ::INT just casts it to a datatype that can be summed. You should take a peak at the datatypes available to find one that best suits your needs. (2 dp might be good for currency)

Another possibility is :

select item, avg( price ) from order group by item;

That's if you don't have a column called "item price" rather 2 columns "item" and "price".

  • Related