What is wrong with this ST_CONTAINS statement PostGIS - Find point in polygon - sql

I'm trying the following:
Event.where('ST_Contains(?,ST_SetSRID(location, 4326)::geography)', search_polygon::geography)
add getting the error
*** NoMethodError Exception: undefined method `geography' for
but without that (::geography) I get a message telling me to cast, what do I do?
HINT: No function matches the given name and argument types. You
might need to add explicit type casts.

It looks like you are trying to use ST_Contains on geography types, but that function only works on geometry types.
If you are OK with the intersects spatial relation (see DE-9IM), then use ST_Intersects(geography, geography).

Related

SQL ''Field" = {variable}' Select by attribute arcpy

I am trying to run a select by attribute where I select all points where "Id" field matches the numeric variable point_id. point_id = 375.
I've tried a few quotation styles and using curly brackets to call my variable. I'm not the most familiar with SQL queries and get an error saying the positional argument follows the keyword string. I have also tried storing my SQL as a variable on it's own called a whereClause and get the same error.
First attempt code
arcpy.management.SelectLayerByAttribute(in_layer_or_view = deer,
selection_type = "NEW_SELECTION",
f'"Id"={point_id}')
Second attempt code
The is a Python issue, not related to ArcGIS or SQL.
You are trying to pass three arguments. For the first two arguments you're using keyword argument (explicitly specifying the argument name: in_layer_or_view = deer), but for the third one you're using positional argument (letting python assign the value to the appropriate argument based on the order of the arguments).
The execption you're getting is telling you that you can't mix the two types this way. Once you started using keyword arguments in the function call, all of the next argument must be passed with their explicit name too.
To fix this, you can use positional argument for all of the arguments (i.e. not specifing argument names at all), or alternatively keep specifing the names for all of the rest of the arguments.
In your case, this should work:
arcpy.management.SelectLayerByAttribute(in_layer_or_view=deer,
selection_type="NEW_SELECTION",
where_clause=f'"Id"={point_id}')
or alternatively:
arcpy.management.SelectLayerByAttribute(deer,
"NEW_SELECTION",
f'"Id"={point_id}')

cypher cast string to integer in Agensgraph

I use the following query, this returns string values:
MATCH (n:artefact) RETURN (n.id)
I'm trying to cast the string to an integer, so I use the following:
MATCH (n:artefact) RETURN toInteger(n.id)
This returns the error:
[FAIL] BadSqlGrammarException->StatementCallback; bad SQL grammar [MATCH (n:artefact) RETURN toInteger(n.id);]; nested exception is org.postgresql.util.PSQLException: ERROR: function tointeger(jsonb) does not exist
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
I've also tried toInt()
I'm guessing the function tointeger(jsonb) does not exist is the issue, is it trying to convert the entire jsonb in an integer rather than just the n.id?
How do I resolve this?
I'm using Agensgraph, when I start agens browser it states check version of AgensGraph ... v1.2 or under

How can I perform a regex/text search on a SUPER type?

What I'm doing now:
I have a table with one field that is a json value that is stored as a super type in my staging schema.
the field containing the json is called elements
In my clean table, I typecast this field to VARCHAR in order to search it and use string functions
I want to search for the string net within that json in order to determine the key/value that I want to use for my filter
I tried the following:
select
elements
, elements_raw
from clean.events
where 1=1
and lower(elements) like '%net%'
or strpos(elements,'net')
My output
When running the above query, I keep getting an empty set returned.
My issue
I tried running the above code and using the elements_raw value instead but I got an issue :ERROR: function strpos(super, "unknown") does not exist Hint: No function matches the given name and argument types. You may need to add explicit type casts.
I checked the redshift super page and it doesn't list any specifics on searching strings within super types
Desired result:
Perform string operations on super field
Cast super field to a string type
There are some super related idiosyncrasies that are being run into here:
You cannot change the type of a super field via :: or cast()
String functions like and strpos do not work on super types
To address both of these issues, you can use the function json_serialize to return your super as a string.

What does the syntax ->* mean?

I have read some documents about the syntax ->*, but i still don't get it. Can anyone explain what it means and in what scenarios I can use it?
I have that syntax in this example:
assign ovs_callback_object->query_parameters->* to <ls_query_params> CASTING.
refvar->* is used to de-reference an unstructured reference variable. For a structured reference, you would use structref->component to access a component of the referenced object (an attribute of an object or a component of a structure). If you have something like TYPE REF TO i, there's no inner structure, so you have to use the special syntax ->*. It's all in the documentation...
The ->* operator is the "Dereference" operator. It turns a TYPE REF TO something into a TYPE something.
In your example, ovs_callback_object->query_parameters is likely a reference, but you don't want to assign the reference to the field-symbol, you want to assign the actual field the reference points to.

can't use pgxml_xpath

I'm using PostgreSQL 9.1, I thought it was supposed to support this XML integration but I can't get it to work. I try this query:
select data from ddm_table_data order by pgxml_xpath(data, '//xmltest/col1/text()', '', '');
And it comes up with the following errors:
ERROR: function pgxml_xpath(xml, unknown, unknown, unknown) does not exist
SQL state: 42883
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Am I missing something?
Am I missing something?
Like the error says - there's no such function. There's one called "xpath" though.
The manuals are your friend.