I live in Denmark. Here the Thousand separator is a dot (.), and we use comma (,) as comma-separator.
I know that you can use TRY_PARSE to convert a varchar into a money/float value.
An example:
declare
#JSON varchar(max)=
'
{
"Data Table":
[
{
"Value" : "27.123,49"
}
]
}
'
select
TRY_PARSE(Value as money using 'da-dk') "Correct Value"
FROM OpenJson(#json, '$."Data Table"')
WITH
(
"Value" nvarchar(255) N'$."Value"'
)
select
Value "Wrong Value"
FROM OpenJson(#json, '$."Data Table"')
WITH
(
"Value" money N'$."Value"'
)
This query gives me two results
My question is: Can I control the culture in the WiTH Clause of OpenJSON, so I get the correct result without having to use TRY_PARSE?
Target: SQL Server 2019
Not directly in OPENJSON(), no. ECMA-404 JSON Data Interchange Syntax specifically defines the decimal point as the U+002E . character - and doesn't provide for cultural allowances - which is why you're having to define culture-specific values as strings in the first place.
The correct way to do it is only using TRY_PARSE or TRY_CONVERT. eg
select try_parse('27.123,49' as money using 'da-DK')
I'm trying to set a rule in Azure Stream Analytics job with the use of reference data and input stream which is coming from an event hub.
This is my reference data JSON packet in BLOB storage:
{
"ruleId": 1234,
"Tag" : "TAG1",
"metricName": "velocity",
"alertName": "velocity over 500",
"operator" : "AVGGREATEROREQUAL",
"value": 500
}
And here is the transformation query in the stream analytics job:
WITH
transformedInput AS
(
SELECT
metric = GetArrayElement(DeviceInputStream.data,0),
masterTag = rules.Tag,
ruleId = rules.ruleId,
alertName = rules.alertName,
ruleOperator = rules.operator,
ruleValue = rules.value
FROM
DeviceInputStream
timestamp by EventProcessedUtcTime
JOIN
rules
ON DeviceInputStream.masterTag = rules.Tag
)
--rule output--
SELECT
System.Timestamp as time,
transformedInput.Tag as Tag,
transformedInput.ruleId as ruleId,
transformedInput.alertName as alert,
AVG(metric.velocity) as avg
INTO
alertruleblob
FROM
transformedInput
GROUP BY
transformedInput.masterTag,
transformedInput.ruleId,
transformedInput.alertName,
ruleOperator,
ruleValue,
TumblingWindow(second, 6)
HAVING
ruleOperator = 'AVGGREATEROREQUAL' AND avg(metric.velocity) >= ruleValue
This is not yielding any results. However, when I do a test with sample input and reference data I get the expected results. But this doens't seem to be working with the streaming data. My use case is if the average velocity is greater than 500 for a 6 second window, store that result in another blob storage. The value of velocity has been greater than 500 for sometime, but I'm not getting any results.
What am I doing wrong?
This was working all along. I just had to specify the input path of the reference blob in the reference input path of stream analytics including the file name. I was basically referencing only the blob container without the actual file. So when I changed the path pattern to "filename.json", I got the results. It was a stupid mistake.
I am trying to build a query, and pass parameters to it,
not sure how can I do it, here is my query
{ "object": "garages", "q": { "lat_long" : { "$within" : [[28.703341,77.130605],10000] } } }
I am passing lat,lng and radios.
Now I am able to pass the params, however in response I get lat_long
as "lat_long": "AAAAAAEBAAAAVYSbjCqfPEDyzTY3pkVTQA==" .
Is it encoded / serialized? How can I'll get my original values?
Thank you,
Point is stored as a binary value, in order to see your original values you have 2 option
You can manipulate the sql statement like this :
SELECT CONCAT(X(lat_long), ',', Y(lat_long)) as origin
FROM garages WHERE (ST_Distance ..........
but this way you want be able to edit the nosql tab
When you call REST API With 'GET' on object 'garages' you'll see the values as you oroginaly Posted them
Could you please help me to find the right solution how to access to the individual points of multi-polygon object in mysql? Here is the object:
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[-105.00432014465332, 39.74732195489861],
[-105.00715255737305, 39.74620006835170],
[-105.00921249389647, 39.74468219277038],
[-105.01067161560059, 39.74362625960105],
[-105.01195907592773, 39.74290029616054],
[-105.00989913940431, 39.74078835902781],
[-105.00758171081543, 39.74059036160317],
[-105.00346183776855, 39.74059036160317],
[-105.00097274780272, 39.74059036160317],
[-105.00062942504881, 39.74072235994946],
[-105.00020027160645, 39.74191033368865],
[-105.00071525573731, 39.74276830198601],
[-105.00097274780272, 39.74369225589818],
[-105.00097274780272, 39.74461619742136],
[-105.00123023986816, 39.74534214278395],
[-105.00183105468751, 39.74613407445653],
[-105.00432014465332, 39.74732195489861]
],[
[-105.00361204147337, 39.74354376414072],
[-105.00301122665405, 39.74278480127163],
[-105.00221729278564, 39.74316428375108],
[-105.00283956527711, 39.74390674342741],
[-105.00361204147337, 39.74354376414072]
]
],[
[
[-105.00942707061768, 39.73989736613708],
[-105.00942707061768, 39.73910536278566],
[-105.00685214996338, 39.73923736397631],
[-105.00384807586671, 39.73910536278566],
[-105.00174522399902, 39.73903936209552],
[-105.00041484832764, 39.73910536278566],
[-105.00041484832764, 39.73979836621592],
[-105.00535011291504, 39.73986436617916],
[-105.00942707061768, 39.73989736613708]
]
]
]
}
This is the actually array of two objects, where the first object has two geometries and the second one. I can access to the geometries of the first object with these queries SELECT AsText( GeometryN( geo_type, 1)) FROM polygon_park; and SELECT AsText( GeometryN( geo_type, 1)) FROM polygon_park; and I get this result
POLYGON((-105.00432014465332 39.74732195489861),(-105.00715255737305 39.7462000683517),(-105.00921249389647 39.74468219277038),(-105.01067161560059 39.74362625960105),(-105.01195907592773 39.74290029616054),(-105.00989913940431 39.74078835902781),(-105.00758171081543 39.74059036160317),(-105.00346183776855 39.74059036160317),(-105.00097274780272 39.74059036160317),(-105.00062942504881 39.74072235994946),(-105.00020027160645 39.74191033368865),(-105.0007152557373 39.74276830198601),(-105.00097274780272 39.74369225589818),(-105.00097274780272 39.74461619742136),(-105.00123023986816 39.74534214278395),(-105.00183105468751 39.74613407445653),(-105.00432014465332 39.74732195489861))
and
POLYGON((-105.00361204147337 39.74354376414072),(-105.00301122665405 39.74278480127163),(-105.00221729278564 39.74316428375108),(-105.00283956527711 39.74390674342741),(-105.00361204147337 39.74354376414072))
, but I do not know how to access to the second object with the following coordinates.
"[-105.00361204147337, 39.74354376414072],
[-105.00301122665405, 39.74278480127163],
[-105.00221729278564, 39.74316428375108],
[-105.00283956527711, 39.74390674342741],
[-105.00361204147337, 39.74354376414072]"
However in both cases I cannot access to the individual points in each geometry.
I need to know this in order to parse this object into json in php.
Thank you a lot in advance!
To access the second object of the first polygon, you use the InteriorRingN(poly, index) where index is 1 based, see the docs for Polygon functions.
So, in your case, you would do:
SELECT AsText( InteriorRingN(GeometryN(geo_type, 1), 1)) FROM polygon_park;
To get individual points use the PointN function of a Linestring. You first have to convert your Polygon rings to Linestrings, for which you can use the Exteriorring or InteriorRingN functions, and then you can access the points.
So, for example, to get the 4th point, of the outer ring of the first polygon, you would do:
SELECT AsText( PointN(ExteriorRing(GeometryN(geo_type, 1)), 4)) FROM polygon_park;
To get the actual values, rather than textual representation, you would use the X and Y functions instead of AsText.
It would possibly have been clearer to use the WKT rather than GeoJSON for you examples, but seeing as there is a one to one mapping between the meaning of parenthesis in WKT and square brackets in GeoJSON, nothing is lost in translation, so to speak.
i can get all polygon on intersects this:-7.9245860488441 -37.122384500713,-7.9245860488441 -37.11904223938,-7.9233955716106 -37.1187601948
SELECT *
FROM propriedades
WHERE ST_Intersects(
ST_GeomFromText(location::geometry),
ST_GeomFromText('POLYGON(-7.9245860488441 -37.122384500713,-7.9245860488441 -37.11904223938,-7.9233955716106 -37.1187601948)'));
propriedades is my table
location is a colunm on are saved geography polygons
the returned error
ERROR: parse error - invalid geometry HINT:
"POLYGON(-7.9245860488441 " <-- parse error at position 25 within
geometry
*** Error ***
ERROR: parse error - invalid geometry SQL state: XX000 Hint:
"POLYGON(-7.9245860488441 " <-- parse error at position 25 within
geometry
solved, i used the geography, no geometry:
SELECT *
FROM propriedades
WHERE ST_Intersects(
location,
'POLYGON((-7.9239281216632 -37.118491021708,-7.9239281216632 -37.116096663161,-7.9240937813677 -37.116105295265,-7.9241591799314 -37.116171875421,-7.9246636046819 -37.116271405188,-7.9259677455811 -37.118572530098,-7.9256079206171 -37.118728486796,-7.9243335012771 -37.118675962065,-7.9243194973485 -37.11849254918,-7.9242705964918 -37.118491021708,-7.9239281216632 -37.118491021708))'
)
but i have other problem, i want intersects > 50 meters
like this http://slimber.com/gallery/pictures2/23/235563/polygons.jpg
There are two problems with the WKT of the polygon, which is why it cannot be parsed. Polygons need two depths of parentheses, and the last coordinate needs to match the first coordinate to make a closed linear ring (i.e., triangles require four points). The WKT should look like this:
POLYGON((-7.9245860488441 -37.122384500713, -7.9245860488441 -37.11904223938,
-7.9233955716106 -37.1187601948, -7.9245860488441 -37.122384500713))
Also ST_GeomFromText(location::geometry) is really unnecessary, since ::geometry is already a PostgreSQL cast operator to geometry. If it is a geography type, then location::geometry should be sufficient to cast it as geometry.