Redshift reserved colume name "TIME" - sql

SELECT customerID
FROM tableA
WHERE TIME= 2023-1-9
AND customerID Is Not Null;
In table A there is a column named as TIME and it stores date value.
as TIME is a reserved term in redshift , how can i call the column from the query?
there is a ERROR: syntax error at or near... from the above query.

Solution for your problem:
SELECT customerID
FROM tableA
WHERE "TIME"= 2023-1-9
AND customerID Is Not Null;
According to redshift docs, double quotation marks(") are required to use reserved words within an identifier.
For more info, please go through the below link:
https://docs.aws.amazon.com/redshift/latest/dg/r_names.html

Related

SQL column name is same as Its function name

There is some Data in the MySQL Workbench. Column name is Left , Right in one table .
Select PersonNumber,Left,Right,PhotoNumbr from Person.
This query is showing is error.
How can I fetch these records ,One thing cannot change column name in table.
Escape in square brackets the column names which are coincident with SQL Server functions:
SELECT PersonNumber, [Left], [Right], PhotoNumbr
FROM Person;
For future reference, do not name your columns using keyword or function names.

BigQuery : How to pass a column name that has the same name as an SQL insturction

Helllo,
I have a table that has an SQL instruction as a column name. I have tried the standard SQL solutions with "limit" or [limit] but they don't work.
SELECT
limit
FROM
table
Regards
To use reserved SQL instruction words as column name, use them in backticks. Or write the table name in front:
select tbl.limit, `limit`
from
(select 1 as `limit`) tbl

How To Reference a Column that has been concatenated in SQL

How do you reference a column in a table that has been concatenated? I am trying to reference the 'UniqueID' column in a join, but all the ways that I have tried it throw the ORA-00904 error saying "T2.UNIQUE ID:Invalid identifier".
create table cdm_user.uniquesubjectIDDEW as (
select distinct concat (site,screening_no) "UniqueID" , visit, site, Screening_no
from databrowser.v_data_entry_workflow
where study = '3508'
);
commit;
Select *
from cdm_user.uniquesubjectIDDEW t1
left join cdm_user.uniquesubjectIDDEW t2
on t1.UniqueID = t2.UniqueID
and t2.visit = 'Screening'
Where t1.visit = 'Week_52'
and t2.visit is null
Any help is much appreciated as I am new to SQL.
Unless quoted, identifiers such as table and columns names will be mapped to upper case. So your select will be interpreted as needing a column name UNIQUEID but you created the column name as "UniqueId" with quotes so it doesn't match.
You'll need to either unquote the name when you create the table or quote it in all queries.
Generally it is better not to use quoted, case-sensitive column names, which is why a lot of databases use underscores in table/column names as word separators rather than some variant of camel case.
Use quoted column name in createing command:
alter table cdm_user.uniquesubjectIDDEW add primary key ("UniqueID");

How to get column names in camelcase in Oracle SQL developer

I am trying to run few queries on Oracle SQL developer
e.g
Select name AS CandidateName, age AS CandidateAge
from tbl_candidate_details
order by candidate_id desc
But In the result I am getting the column names as "CANDIDATENAME" AND "CANDIDATEAGE".
Is there a way where I can get this as camelcase characters what I have given in the select statement("CandidateName" and "CandidateAge") ?
If the column aliases are wrapped in double-quotes, SQL Developer will use those exact values as the column names in the query results:
SELECT name AS "CandidateName", age AS "CandidateAge"
FROM tbl_candidate_details
ORDER BY candidate_id DESC;
Otherwise, the column names in the query results are always displayed in upper case
SQL is case insensitive and the SQL standard requires to fold all un-quoted identifiers to uppercase. If you want to preserve the case of your identifiers you need to quote them:
Select name AS "CandidateName",
age AS "CandidateAge"
from tbl_candidate_details
order by candidate_id desc

How to convert an invalid number column to a number on HANA?

I have a table with a string column. I convert this column to a number using the function TO_INTEGER(). Ist work fine. But If I Aggregate the converted column with the function SUM I got this error:
SAP DBTech JDBC: [339]: invalid number: not a valid number string ' ' at function to_int()
This is my sample SQL query:
select SUM(PARTICIPANT)
from (
select TO_INTEGER(STUDENT) as PARTICIPANT
from MyTable)
Column STUDENT is a varchar(50) in MyTable
What did I do wrong?
Thanks in advance
Without seeing your Column values, it looks like you're trying to convert the numeric sequence at the end of your values list to a number, and the spaces that delimit it are throwing this error. But based on the information you've given us, it could be happening on any field.
Eg:
Create table Table1 (tel_number number);
Insert into Table1 Values ('0419 853 694');
The above gives you a
invalid number
Kindly Check Filter/ where clause if you try to give string column value as integer that time you got this error message. I wrote in HANA - Calculation view - SQL Script, In where clause Bukrs (Company Code) = 1000 after that i changed Bukrs = '1000'. then this issue is resolved.