Unable to use ST_Intersects on geometry field - gis

I have converted the Personal Geodatabase of ESRI (*.mdb file) into the PostGIS enabled PostgreSQL database using FWTools. On which I get my geometry field named as wkb_geometry as follows
wkb_geometry geometry(Geometry, 3148),
While querying the database using ST_Intersects on where I get following error
SQL
SELECT <other fields>,
"wkb_geometry" AS "_smtmp_" FROM parcel WHERE <condition>
AND ST_Intersects(((E'\\001\\003\\000\\000 L\\014\\000\\000\\001\\000\\000\\000\\005\\000\\000\\000\\020\\2625\\334i\\032\\034A\\273n\\256E\\033\\340GA\\020\\2625\\334i\\032\\034A\\017\\261\\014\\353\\037\\340GA\\262\\304\\047\\007\\217\\032\\034A\\017\\261\\014\\353\\037\\340GA\\262\\304\\047\\007\\217\\032\\034A\\273n\\256E\\033\\340GA\\020\\2625\\334i\\032\\034A\\273n\\256E\\033\\340GA'))
,"wkb_geometry")
Error
ERROR: parse error - invalid geometry
LINE 1: ... parcel WHERE parcelno < 50 AND ST_Intersects(((E'\001\0...
HINT: "\0" <-- parse error at position 2 within geometry
ERROR: parse error - invalid geometry
SQL state: XX000
Hint: "\0" <-- parse error at position 2 within geometry
Character: 245
I am using SharpMap in front end.

The problem here is not with the geometry field, but with the query.
You should use the ST_GeomFromEWKB function like this
SELECT <other fields>,
"wkb_geometry" AS "_smtmp_" FROM parcel WHERE <condition>
AND ST_Intersects(ST_GeomFromEWKB(E'\\001\\003\\000\\000 L\\014\\000\\000\\001\\000\\000\\000\\005\\000\\000\\000\\020\\2625\\334i\\032\\034A\\273n\\256E\\033\\340GA\\020\\2625\\334i\\032\\034A\\017\\261\\014\\353\\037\\340GA\\262\\304\\047\\007\\217\\032\\034A\\017\\261\\014\\353\\037\\340GA\\262\\304\\047\\007\\217\\032\\034A\\273n\\256E\\033\\340GA\\020\\2625\\334i\\032\\034A\\273n\\256E\\033\\340GA')
,"wkb_geometry")

Related

postgresql jsonpath support

I am running postgresql 12 and am trying to use jsonpath.
I'd like to use jsonb_path_query_first to get the length of an array. I know I can do json_array_length but would rather not.
Here is the query that I am trying to make work.
select jsonb_path_query_first('{"a":3,"b":6,"s":[1,2,3,4,5], "d":{"v":4}}'::jsonb, '$.s.length()'::jsonpath);
ERROR: syntax error, unexpected '(', expecting end of file at or near "(" of jsonpath input
LINE 1: ...a":3,"b":6,"s":[1,2,3,4,5], "d":{"v":4}}'::jsonb, '$.s.lengt...
Does the version of jsonpath in postgresql 12 not support this type of jsonpath functionality.
You can use the .size() method for this:
test# select
jsonb_path_query_first(
'{"a":3,"b":6,"s":[1,2,3,4,5], "d":{"v":4}}'::jsonb,
'$.s.size()'::jsonpath
);
jsonb_path_query_first
════════════════════════
5
(1 row)

ERROR: invalid input syntax for type json Detail: The input string ended unexpectedly. Postgresql

I'm trying to obtain information from a API's response in the DB. The column is a text type.
So I'm using the following code in the SELECT part:
SELECT KA.id,
KA.response::json -> 'SearchComplianceAlertsResponse' -> 'TransactionResult' ->> 'ResultText' AS result_text,
KA.response::json -> 'SearchComplianceAlertsResponse' -> 'TransactionResult' ->> 'ResultMessage' AS result_description
FROM KA
When I export that as a CSV I'm getting weird information at the end of the CSV:
Also, when I try to join the table with the code from above I'm getting the error mentioned in the title of the question. But When I run the query separately I don't have any issues running it.

What is the PotgreSql equivalent of a mysql query using Sgt_asText(point(longitude, latitude))

I would like to use a point with longitude and latitude in the following Postgres query (at the end of post), but I get this error:
ERROR: function st_astext(point) does not exist
LINE 1: ...CONCAT_WS(',', 'GEOMETRYCOLLECTION(',group_concat(st_asText(...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
SQL query :
SELECT ogc_fid, name, CONCAT_WS(',', 'GEOMETRYCOLLECTION(',group_concat(st_asText(point(longitude, latitude))),',',st_astext(geometry),')') as shape FROM locationshape WHERE locationshape.location_id IS NULL AND st_contains(geometry, point(longitude, latitude));
point() creates a point, i.e. a native postgres type.
ST_point() will create a point geometry, which is a Postgis type and which can be used in other PostGIS functions such as st_asText
select st_asText(st_point(1,2));
st_astext
------------
POINT(1 2)
(1 row)
That being said, you may want to have a look at st_collect to create the geometrycollection from geometries, not from text.

MySQL JSON data type and JSON_ARRAY_APPEND does not work

I am struggle with JSON and MySQL. I am trying to append to a JSON object.
Object has this form:
[{},{},...]
SELECT JSON_ARRAY_APPEND(my_meta, '$[0]', '{"private_key": "adfadf"}')
FROM my_object where user_id='11111'
I get the below error using 5.7.8-rc
Error Code: 1305. FUNCTION JSON_ARRAY_APPEND does not exist
So how do append then given I follow the docs?

How to call mysql date_format function in JPQL

I'm developing a webservice using eclipseLink 2.4.1, JPA 2.0.1 and other supporting tools. I have created a table which has a column of date type. I want to get records of a particular date. I'm using date_format of mysql and getting following error:
java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Syntax error parsing[select o from Clients o where FUNCTION('date_format',{o.effectiveStartDate},{d,'dd-mm-yyyy'})='27-05-2014']
[90, 111] The JDBC escape format does not start with either 'd', 't' or 'ts'.
[110, 110] The JDBC escape format is missing the close quote.
Even I tried to call date_format directly as :
Select o from Clients o where date_format(o.effectiveStartDate '%d-%m-%Y'})='27-05-2014'
Then I get syntax error parsing. invalid token [(].
I tried with namedQuery also but didn't get success.
How to call such function JPQL.
What is "{o.effectiveStartDate}" trying to do ? Remove the curly brackets or it will try to interpret that as a JDBC escape syntax date (which it isn't).
JPA 2.1 'FUNCTION' syntax would be
FUNCTION("date_format", o.effectiveStartDate, "the_date_format")
where "the_date_format" matches what MySQL accepts for its second arg as per http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format
That of course requires you to use a JPA2.1 compliant implementation; your implementation may have some other vendor-specific FUNC or otherwise which is not portable and I've no time for when there's a standard variant that should do what you need