How to fix 'error: Error: syntax error - at value' - node.js

I have objects like:
address: {
"phone" : 888,
"value" : 12
}
And in WHERE i need to find objects by address.value, but in SQL there's function value(), so i always get an error.
I do it from node.js. Are there any variants to solve this without changing objects?
Sql request like:
SELECT count(*) as size FROM addresses WHERE address.value = 12

VALUE is a reserved word. If you want to use it as a common identifier, you need to enclose it in backticks:
SELECT count(*) as size FROM addresses WHERE address.`value` = 12

Related

ADF: Pass dynamic Where Clause as a string with quotes

I have a lookup that retrieves a few records from a SQL Server table containing server, database, schema, table name and a whole where clause. These values are passed to a copy data (within a ForEach) In the copy data i have tried to use two different Dynamic query statement, but I seem to get an error. And can't figure out where I'm going wrong.
Values in table:
SRC_SERVERNAME
SRC_DATABASE
SRC_SCHEMANAME
SRC_TABLENAME
SRC_WHERE_DATE_CLAUSE
SQ01
NAV
dbo
Company$Sales Invoice Header
where [Posting Date] >= '2021-01-01'
Source setup:
Error for statement 1:
A database operation failed with the following error: 'Incorrect syntax near '.'.'
Incorrect syntax near '.'., SqlErrorNumber=102,Class=15,State=1,
Error for statement 2:
A database operation failed with the following error: 'Incorrect syntax near '.'.'
Incorrect syntax near '.'., SqlErrorNumber=102,Class=15,State=1,
Statement 1 (query):
SELECT *
FROM #{item().SRC_SERVERNAME}.#{item().SRC_DATABASENAME}.#{item().SRC_SCHEMANAME}.#{item().SRC_TABLENAME},' ',#{item().SRC_WHERE_DATE_CLAUSE}
Statement 2 (dynamic query with concat):
#concat('select * from ',item().SRC_SERVERNAME,'.',item().SRC_DATABASENAME,'.',item().SRC_SCHEMANAME,'.',item().SRC_TABLENAME,' ',item().SRC_WHERE_DATE_CLAUSE)
There is a syntax error in your query.
In the 4-part naming of SQL database, server name/database name/schema name/table name should be separated by ‘.’.
When you have space or other special characters in the name of server/database/schema/table, they should be embedded inside square braces [].
#concat('select * from [',item().SRC_SERVERNAME, '].[',item().SRC_DATABASENAME,'].[',item().SRC_SCHEMANAME,'].[',item().SRC_TABLENAME, '] ',item().SRC_WHERE_DATE_CLAUSE)

'id' in where clause is ambiguous

I have a table with some fields and some relations with others.
I get the list view with no problem, but when I try to filter the results (using the search feature in flexigrid table) I get:
A Database Error Occurred Error Number:
1052Column 'id' in where clause is ambiguousSELECT
gee_job_boards.*, j32e2cb0f.dp_name AS s32e2cb0f FROM
gee_job_boards LEFT JOIN gee_distribution_partner as j32e2cb0f
ON j32e2cb0f.id = gee_job_boards.dp_id WHERE id LIKE '%27%'
ESCAPE '!' LIMIT 25Filename:
models/Grocery_crud_model.phpLine Number: 87
Error Number: 1052Column 'id' in where clause is
ambiguous
how could i solve this ?
thanks
You should qualify your id in where clause, for example like this
j32e2cb0f.id LIKE ...

Cosmos DB: Querying documents properties with special characters such as "$"

I've got a Cosmos DB collection with a document that contains properties that have a special character and what I assume is a reserved word. An example document is:
{
$type: 'Some value',
Value: 'Some other value'
}
If I execute the following query in the Azure Portal Query Explorer:
select * from c where c.Value = 'Some other value'
I receive an error of "Syntax error, incorrect syntax near 'Value'.". I get a similar error querying on c.$type.
How do I escape these property values so that I can query?
In the case of special characters, you will need to wrap the property inside []
Example:
SELECT * FROM c WHERE c["$type"] = "Some value"
SELECT * FROM c WHERE c["value"] = "$Some other value"

DocumentDB Stored Procedure Lumenize

I'm using the aggregate stored procedure lumenize https://github.com/lmaccherone/documentdb-lumenize with the .net client and I'm in trouble in the filterquery content.
How simply pass alphanumeric value to the filterquery query ?
string configString = #"{
cubeConfig: {
groupBy: 'Modele',
field: 'Distance',
f: 'sum'
},
filterQuery: 'SELECT * FROM Modele WHERE ModeleGUID = ''0b93def1-ccd7-fc35-0475-b47c89137c3f'' '}";
Each test gives me a parse error in the filterquery :(
Error: One or more errors occurred.
Message: After parsing a value an unexpected character was encountered:
'. Path 'filterQuery', line 7, position 63.
End of demo, press any key to exit.
Thanks
Just to properly close this out: The issue is related to multiple single-quotes in the filter string. As long as they're escaped properly (e.g. \'), things should work as expected.

In Azure DocumentDB some queries don't work

I used Azure DocumentDB to store some Key-Values pairs. This is the structure of the document I used
{
"Key": "Deleted",
"Value": {
"email": "abc#cdf.com"
}
}
When i write DocumentDB query like this,
SELECT C.Value FROM C
This query does not work. Here is the error message I get.
Syntax error, incorrect syntax near 'Value'.
But this query works fine,
SELECT C.Key FROM C
I understand 'Value' should be a keyword in azure documentdb. How can i query it?
Value is a keyword in DocumentDB syntax so this is why you get an error. See Value keyword in this article DocumentDB syntax - The VALUE keyword provides a way to return JSON value.
To get around this you can query it the way Yannick has said i.e.
SELECT C['Value'] FROM C
Because your documents are stored as JSON, you can access them as follows:
SELECT C['Value'] FROM C
This will result in:
[
{
"Value": {
"email": "abc#cdf.com"
}
}
]
In DocumentDB query grammar, the syntax < collection_expresion >.property_name is exactly same as < collection_expression >["property_name"]. So, effectively,
c.name
is same as
c["name"]
The syntax < collection_expression >["property_name"] allows one to derefence properties which might have non-identifier characters like 'my value' (space between my and value), or keywords like 'Value', 'Select' etc.
Hence,
SELECT C["Value"]
FROM C
will work in your case.

Resources