Search code examples
sqlamazon-web-servicesamazon-redshift

T-SQL alias '=' not working in AWS Redshift


I found that aliasing using the '=' format is not working in AWS Redshift. Is there any possible way to resolve this without changing on existing query?

In SQL Server:

select fileid AS ID from tableA     -- Working 
select [ID] = fileid from tableA    -- Working

In AWS Redshift:

select fileid AS ID from tableA    -- Working 
select [ID] = fileid from tableA   -- Fails, will return ERROR: column id does not exist in table A.

Solution

  • [ID]=fileid is a boolean expression, returning TRUE if the column [ID] value is equal to the column fileid value. (ISO/ANSI SQL-2023, optional feature T031, BOOLEAN data type.)

    But you have no column [ID], hence the column id does not exist error.

    Conclusion, do this the ANSI/ISO SQL way:

    select fileid AS ID from tableA