How to eliminate Query error: 403 in Grafana? Example is a Substring - substring

I'm trying to receive a result similiar to '13:49:31' in this panel. Here is the code:
select SUBSTRING(CONVERT(VARCHAR,DATEADD(HOUR,-3,SYSDATETIME())),12,8)
This is the message: "Query error: 403"
I copied the code and executed it at SQL Server Management Studio and it worked.
If I remove the substring function, it works. Like this "select CONVERT(VARCHAR,DATEADD(HOUR,-3,SYSDATETIME()))"
However, I really need this format '13:49:31'

Related

Why do I get a "unterminated quoted string at or near" error using python postgresql, and not in pgadmin, whith the same request?

I have this query :
INSERT INTO lytnobjects.devices (id,idedge,uniqueref,constructeur,ipaddress,macaddress,
hostname,devicetype,isfirewall,isvisible,iscorporate,
ishub,osname,osversion,datecreation,lasttrafic,
hourtrafic,daytrafic,monthtrafic)
VALUES ('e1e455e98b6ed0037a58d0c1f5dc245a',3183,'TODO','TODO','192.168.143.49',
'b0:0c:d1:bb:36:1c','HPBB361C','Other',False,False,False,False,'','',
'2021-10-29T00:58:53.709','2021-01-01T00:00:00','0/0','0/0','0/0')
When I execute the query using python 3.9 and psycopg2_binary (PostgreSQL), I get an error :
unterminated quoted string at or near "'HPBB361C"
conn is the opened connection to the database (AWS RDS PostgreSQL)
sql is a string with the query above
def SQLExec(conn,sql):
try: cur = conn.cursor()
cur.execute(sql)
except (Exception, psycopg2.DatabaseError) as error:
print("***** ERROR:",error)
cur.close()
If I execute the same request from pgAdmin, I get no error !
There is no missing quote as you can see in the query, and no reason to point an error at this place!
So, I have a string (sql) with the query ("INSERT ...")
I call execute from psycopg2, and get an error: unterminated quoted string at or near "'HPBB361C"
I copy/paste the same string into pgAdmin, and the query is executed with no error
The same string (query)
Any idea why I get an error from my python app?
I am looking for an answer since many hours, but find no explanation, and I don't know how to fix the problem (which doesn't exist for me)
Your help is very appreciated
Thank you
I finaly found the answer!
I build the sql query (string) using some variables coming from various sources, like Amazon S3 for instance.
I assumed that the variable was really a string, with nothing "bizarre" in it... But in fact, sometimes, the "string" was ended with a "\x00" char, that is not displayed, so the string looks just normal :-/
When I execute my query (string) with psycopg2, it receives the extra \x00 char, which ends the string at this place! This is why it says there is a missing quote
I put a trace in the code to display the .encode() version of my string, and it revealed the \x00 at the end. So now I "clean" all string variables used in my queries, just with myvariable.replace("\x00","")
And it works now. There is probably a more conventional way to fix this...
I hope it may help somebody sometime! ;-)

How to correct use $X in jasper??. Problem with parameters and IN clause in JSS

I have a report made with Jaspersoft Studio and in the dataset query I need to use an IN clause, for that I am using the expression "$X{IN ..."
Question # 1: What is the correct type to use for the parameter?
I'm using the following format:
Question # 2: How do I test in the preview?
Parameters screen:
To help, follow the excerpt of where with the parameter being used:
"...Where (($X{IN, db.empresa, paramIdEmpresa}) OR $ P!{ParamIdEmpresa} IS NULL) and (db_view ... "
Error that appears in the preview with the above parameters:
net.sf.jasperreports.engine.JRException: Error executing SQL statement
for: unit1. at com.jaspersoft.studio.editor.preview.view.control.ReportController.fillReport
(ReportController.java:551) at com.jaspersoft.studio.editor.preview.view.control.ReportController.access
(BaseFillHandle.java:135) at java.lang.Thread.run (Thread.java:748)
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at
or near "["   Position: 199 at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse
(QueryExecutorImpl.java:2440) at
org.postgresql.core.v3.QueryExecutorImpl.processResults
the problem was in the query and not in jasper...
the correct query is:
where
(($X{IN,db.idempresa, paramIdEmpresa}) OR db.idempresa IS NULL )
thanks to GP...
The best possible way to solve it is simple:
create a parameter called $P!{paramWhere}. of your application
pass the complete where clause with this parameter, e.g. "id = 200"
In your query inside jasper, you put it like this: "... select * from <anywhere> where $P!{paramWhere} ..." and it will magically work.

FB3.0 Dateadd() throws syntax error in where section of query

I am trying to compare the date modified (field type: Timestamp) with a value that is based off of a month before the current date. I keep getting a syntax error when using the function DateAdd().
I Am Using Libreoffice base 6.2.3.2 (x64) and firebird 3.0 embedded
Using this code, I get a result returning no records but no error
Select *
From "tblPart"
Where "Date Modified" = Current_Timestamp
but anytime I want to use the Dateadd() function, I get an error
Select *
From "tblPart"
Where
"Date Modified"< Dateadd(Month,-1,Current_Timestamp)
Expected to Return a list of results that have been modified over a month ago.
Errors:
SQL Status: HY000
Error code: 1000
Syntax error in SQL statement
SQL Status: HY000
Error code: 1000
SQL Status: HY000
Error code: 1000
syntax error, unexpected $end, expecting BETWEEN or IN or SQL_TOKEN_LIKE
//EDIT: Added the programs that I used
I ran into the same problem. Though the SQL-statement with DateAdd() has been suggested as working, LO Base answered the query with a message box
Syntax error in SQL statement
Why it should work
In contrast the same SQL statement like in the query succeeded by running it in the "Execute SQL Statement" window (LO Base' main window menu "tools" > "SQL…").
Solution
What finally got my query to work was to check "Run SQL command directly" in the toolbar or in the "Edit" menu.
This prevents LO from analyzing the SQL query before execution. This fails, because it is not understanding the full SQL statement (firebird's DateAdd()-function), and thus is the reason for the mentioned errors.

Syntax error on DB2 XMLELEMENT

I get this error when trying out this command in the BIRT Classic Models sample database in Data Studio
select xmlelement(name "custno", customers.customernumber) from customers
Syntax error: Encountered "\"custno\"" at line 1, column 24.
I do not know how to correct it.
Thanks.
I'm not familiar with db2, but according to this your statement looks quite alrigth (although I'd place an alias to name this field...)
But this
Syntax error: Encountered "\"custno\"" at line 1, column 24.
seems to be a quite clear hint, that your error is connected to the NAME of the element.
I'm pretty sure, that this statement was created on string level.
Did you try to escape the "-characters with \"?
The SQL reaching the engine might look like
select xmlelement(name \"custno\", customers.customernumber) from customers
or
select xmlelement(name "\"custno"\", customers.customernumber) from customers
... which is wrong of course...
But to be honest: just guessing...

Progress DB charindex syntax error

I'm trying to create a query in progress DB that gets the name portion off the email address. This is what I have so far:
substring("PUB"."NAME"."INTERNET-ADDRESS", 1, CHARINDEX('#', "PUB"."NAME"."INTERNET-ADDRESS") ) as Name
However, I'm getting a syntax error around the CHARINDEX(...
I'm not a progress guy and knowing SQL is just enough to get me into trouble...
Do you see the error in my ways?
Try this:
substring("PUB"."NAME"."INTERNET-ADDRESS", 1, INSTR("PUB"."NAME"."INTERNET-ADDRESS",'#') ).
Here you have the entire suite of documentation:
https://community.progress.com/community_groups/openedge_general/w/openedgegeneral/1329.openedge-product-documentation-overview