I have a script that used to run just fine from Teradata SQL Assistant. I am unable to get the exact same script to run from SQL Workbench/J. I have isolated the problem to one specific line. Here's the query:
SELECT
variable1 as name1,
variable2 as name2,
CONCAT(TRIM(variable3), ':', trim(variable4)) as name3
variable4 as name4,
FROM
table1
WHERE
variable4 between '2017-01-01' AND '2017-01-31';
The problem is the CONCAT line. If I comment that line out, code runs fine. If I leave that line in, I get the unhelpful message:
[Teradata Database] [TeraJDBC 16.10.00.07] [Error 3706] [SQLState 42000]
Syntax error: expected something between '(' and the 'TRIM' keyword. [SQL State=42000,
DB Errorcode=3706]
1 statement failed.
I say unhelpful, because that makes it sound like a syntax error, but this isn't a syntax error as far as Teradata is concerned. The exact same code ran fine on Windows Teradata SQL Assistant. But since OSX Teradata SQL Assistant is a dumpster fire, I have to try and run the script in SQL Workbench J.
Help, please?
There's no concat function in Teradata SQL, it's an ODBC function (sometimes) automatically translated by the ODBC driver to valid syntax. But SQL Workbench uses JDBC, which doesn't support this function.
Simply switch to Standard SQL ||:
TRIM(variable3) || ':' || trim(variable4)
Related
I am trying to run the following Firebird SQL query in LibreOffice, which has embedded Firebird:
SELECT RDB$GET_CONTEXT('SYSTEM', 'ENGINE_VERSION') AS "VERSION"
FROM "RDB$DATABASE";
I get the message Syntax error in SQL statement. Can anyone tell me what I am doing wrong? This works in FlameRobin, but not in LibreOffice.
The error "Syntax error in SQL statement" is a HSQLDB error. So, first, make sure your LibreOffice Base project is actually created as a Firebird Embedded project.
I was able to reproduce the error in LibreOffice Base 6.4.4.2 with a Firebird Embedded project. It looks like LibreOffice first tries to parse the query using HSQLDB (probably to be able to transform HSQLDB syntax to Firebird syntax), and only then forwards it to Firebird.
The cause of the error is the $ in RDB$GET_CONTEXT which is not a valid character in an unquoted object name in the HSQLDB SQL syntax, while it is valid in the Firebird SQL syntax. Normally, double quoting the specific object name would solve this, but RDB$GET_CONTEXT is not actually a function, but a syntax construct, so it can't be quoted in Firebird.
To be able to execute this query, you need to enable the 'Run SQL command directly' option in the SQL View, either under Edit > 'Run SQL command directly', or using the 'Run SQL command directly' button in the toolbar (database icon with >_).
I'm getting an error at this statement:
cursor.execute("SELECT * FROM dbo.User")
Error:
pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near the keyword 'User'. (156) (SQLExecDirectW)")
The code is below. I'm assuming the connection is fine because nothing happens unless I execute the query? Am I doing something wrong?
SERVER = 'LAPTOP-1E7UL24T\SQLEXPRESS02'
DATABASE = 'PT'
DRIVER='{ODBC Driver 17 for SQL Server}'
DATABASE_CONNECTION=f'Driver={DRIVER};SERVER={SERVER};Database={DATABASE};Trusted_Connection=yes;'
print(DATABASE_CONNECTION)
cnxn=pyodbc.connect(DATABASE_CONNECTION)
cursor=cnxn.cursor()
cursor.execute("SELECT * FROM dbo.User")
User is a reserved word and needs to be escaped, commonly by using square brackets e.g.
SELECT * FROM dbo.[User]
But double quotes also work:
SELECT * FROM dbo."User"
Although it will make your life (and any developers who follow) a lot easier if you just avoid using reserved words.
Most likely you are running into the deprecated data types: IMAGE, TEXT and NVARCHAR. They need to be handled differently.
See their github issue, and this SO answer.
I am trying to execute simple select query with SKIP LOCKED DATA
but getting syntax error. Below is the sample query
SELECT ELEMENT FROM WORKQUEUE
WHERE PRIORITY = '1' AND STATUS='OPEN'
SKIP LOCKED DATA;
Got error as below
DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=SKIP;
<query_expression>;END-OF-STATEMENT, DRIVER=3.61.86
But as per documents it is valid query. Please let me know if I am doing something wrong?
I suspect you are not using Db2 for z/OS 10.0.0
I suspect you are using e.g Db2 11.1 and you need a manual page from that Db2 platform such as
"Evaluate uncommitted data through lock deferral" - https://www.ibm.com/support/knowledgecenter/SSEPGG_11.1.0/com.ibm.db2.luw.admin.perf.doc/doc/c0011218.html
because Db2 for Linux, Unix and Windows does not support the SKIP LOCKED DATA clause directly
I just set up a teradata JDBC database through Oracle SQL Developer. I can't get the 'DESCRIBE' command to work, or the 'HELP TABLE' command (usually the case with teradata).
If I put in DESCRIBE tablename ; I get error:
[Teradata Database] [TeraJDBC 14.10.00.26] [Error 3706] [SQLState 42000] Syntax error: expected something between the beginning of the request and the word 'DESCRIBE'.
If I use HELP TABLE tablename ; it gives me a help menu internal to Oracle sql developer
Anyone else have this issue? or know any alternatives to the DESCRIBE command?
Try this:
SHOW TABLE $database.$table
Trying to execute the statement
select *
from RU_VARIANCE_HISTORY
but I'm getting the error
DB2 SQL Error: SQLCODE=-901, SQLSTATE=58004,
SQLERRMC=Invalid collation ID, DRIVER=4.21.29
Tried searching but unable to find the solution.
This can happen if DB2 thinks the statement is really too long or too short. Try adding a semicolon to the end of your statement - this worked for me with the same error.