I have a Teradata query that runs correctly in the Teradata SQL Assistant, but shows an error when written in a sqoop script.
The query does a join on three tables using a condition like this:
...
From tableA as A \
Inner Join tableB as B\
Inner Join tableC as C \
On (B.ID = C.ID and (100*year(A.dt) + month(A.dt)) = C.curr_dt) \
...
The error that I get in sqoop comes from the multiplication.
15/01/06 00:44:01 ERROR manager.SqlManager: Error executing statement: com.teradata.jdbc.jdbc_4.util.JDBCException: [Teradata Database] [TeraJDBC xx.yy.zz.ww] [Error 3706] [SQLState 42000] Syntax error: expected something between '*' and the 'year' keyword.
Is it not possible to do arithmetic operations during a join in sqoop? I haven't found any resources to help me out with this. Any help would be appreciated.
Thanks!
YEAR and MONTH are not valid Teradata SQL, both are ODBC syntax, which is automatically rewritten by the ODBC driver.
Try EXTRACT(YEAR FROM A.dt) instead.
Related
I have to create an SQR that generates a list of EEIDs, if there were any changes to the Pension data in the past day. The SQR compiles and works perfectly when I hardcode in the table names.
However, when I tried using variables for the table names, I get a compile error
I've pasted the portion of SQR that I'm trying to fix
When I start using $tableName and $auditTableName as table variables, that's when I get the error and I'm not sure what is going wrong
Can anyone help?
Please and Thank You
!***************************
begin-procedure Process-Main
!***************************
let $tableName = 'PS_PENSION_PLAN'
let $auditTableName = 'PS_AUDIT_PENSION_PLN'
let $dummy-dyn-variable = ''
begin-SELECT DISTINCT
L.EMPLID
L.EMPL_RCD
do someProcName(&L.EMPLID, &L.EMPL_RCD)
FROM [$dummy-dyn-variable]
(
SELECT DISTINCT
PP.EMPLID,
PP.EMPL_RCD,
PP.EFFDT,
'1901-01-01 12:00:00' AS AUDIT_STAMP
FROM [$dummy-dyn-variable] [$tableName] PP
UNION
SELECT DISTINCT
A.EMPLID,
A.EMPL_RCD,
A.EFFDT,
A.AUDIT_STAMP
FROM [$dummy-dyn-variable] [$auditTableName] A
)L
WHERE DATEDIFF(DAY,CAST(L.AUDIT_STAMP AS DATE),SYSDATE) = 1
ORDER BY 1,2
end-SELECT
end-procedure
Edit:
does the UNION have anything to do with this?
I keep receiving is this error:
(SQR 5528) ODBC SQL dbdesc: SQLNumResultCols error 102 in cursor 1:
[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'FROM'.
(SQR 5528) ODBC SQL dbdesc: SQLNumResultCols error 8180 in cursor 1:
[Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.
Edit2:
Ok, initial problem solved with [$dummy-dyn-variable], which led to the next problem with the DO command. I've updated the code above with DO someProcName(param_a, param_b)
I am now getting an error saying:
(SQR 2002) DO arguments do not match procedure's
Weird part, if I remove the dynamic table variables and hardcode the table names in the FROM section, then it compiles properly without errors. This makes me believe that the error is not related to my someProcName (maybe?)
am I missing something here?
I have a query that works perfectly in SSMS. But when running the query in R using the DBI package, I receive several multipart identifier errors: The multi-part identifier: "rt.secondary_id" could not be bound, "rt.third_id" could not be bound, and "t2.important" could not be bound.
select t1.[main_id]
,rt.secondary_id
,rt.third_id
,t1.[date_col]
,t2.important
from t1
inner join rt on t1.main_id = rt.main_id
inner join t2 on rt.main_id = t2.main_id
inner join (select t1.main_id, max(t1.date_col) as upload_time from t1 group by t1.main_id) AS ag ON t1.main_id = ag.main_id AND t1.date_col = ag.upload_time
The unique identifier in t1 is the combination of main_id and date_col, and this query finds the most recent entry in t1 for a given main_id.
Not exactly sure if my query is structured in a poor way or this is an R issue. I've tried adding SET NOCOUNT ON to the query based on what I thought might be related issues elsewhere on stackoverflow, but no dice.
I found out what my issue was- silly (but time consuming) mistake on my part... but essentially, I was bringing my SQL query into R via paste(scan(...), collapse = " "). I had a comment in my SQL query, --, which could not be read correctly by R. Deleting the comment OR switching the comment to /* ... */ syntax fixes the problem.
I am using the R DBI package to query a oracle database.
When using inner joins it gives me the following error.
Plain SELECTS without INNER JOIN works fine. Why?
Error: nanodbc/nanodbc.cpp:1617: 00000: [Oracle][ODBC][Ora]ORA-00933: SQL command not properly ended
DBI::dbGetQuery(con_ora, "SELECT dat.LP_ZP_ID, dat.LP_TIMESTAMP_LOC, dat.LP_WERT, zp.ZP_ZAEHLPUNKT
FROM EDM_LP_DATEN dat
INNER_JOIN EDM_ZAEHLPUNKT zp ON zp.ZP_ID=dat.LP_ZP_ID
WHERE dat.ZP_ID = 111 AND dat.LP_TIMESTAMP_LOC >= TIMESTAMP '2021-01-01 00:00:00'")
What's obviously wrong is this:
INNER_JOIN EDM_ZAEHLPUNKT
It is not inner_join but inner join (without underscore).
The rest of your query looks OK.
I am trying to run the below bteq script in unix.
BTEQ -- Update.txt
.LOGON i.p/username,password
.set width 132
.set errorout stdout
sel date, time;
.set maxerror 1
Nonsequenced validtime
update SCHEMA_1.TABLE_1
set ef_dtm = period( timestamp '1900-01-01 00:00:00.999999',
end(ef_dtm))
where begin(ef_dtm) > CURRENT_TIMESTAMP
and end(ef_dtm) = to_date('12/31/9999', 'mm/dd/yyyy')
.quit
But i am getting the below error
*** Failure 3706 Syntax error: Invalid use of JSON entity reference syntax on non-JSON type.
Statement# 1, Info =0
Exiting BTEQ... RC (return code) = 8
Please note that if I run the update statement along with nonsequenced
valid time directly in SQL Assistant, it works without any issue.
Can you please help me fix this?
Let me know if you need any more info.
User semicolon at the end of update statement.
I submitted a simple (so I thought) query via RODBC :
ch <- odbcConnect(dsn.name, believeNRows=FALSE, rows_at_time=1)
sqlQuery(ch, "CURRENT_TIMESTAMP()")
And it threw the following error:
[1] "42000? -1 Malformed SQL Statement: Unrecognized keyword: CURRENT_TIMESTAMP\r\nStatement:CURRENT_TIMESTAMP()"
[2] "[RODBC] ERROR: Could not SQLExecDirect 'CURRENT_TIMESTAMP()'"
I thought CURRENT_TIMESTAMP() is a common SQL command and didn't expect this to not run. I had checked that the ODBC connection (RSSBus DynamicsCRM Source x64) supports CURRENT_TIMESTAMP(). My connection is OK, I was able to perform some other SQL queries.
So is there a problem with my syntax above? Or is there a list of keywords that RODBC doesn't recognise?
In the above code, first line i.e.
ch <- odbcConnect(dsn.name, believeNRows=FALSE, rows_at_time=1)
creates a connection to your ODBC data source name (dsn.name). So here ch basically stores the connection instance. The second line:
sqlQuery(ch, "CURRENT_TIMESTAMP()")
executes the SQL query on the connection i.e. ch and returns the result in a data frame. So instead of using the method CURRENT_TIMESTAMP() use complete query:
sqlQuery(ch, "SELECT CURRENT_TIMESTAMP()")
I hope this will help.