Postgis: function st_contains does not exist - postgresql

I am struggling to get a simple Postgresql/Postgis statement to work, I need all points within a polygon (in this case a rectangle)
SELECT * FROM points_table WHERE ST_Contains( ST_GEOMFROMTEXT('POLYGON((51.8121, 0.13712199999997665, 51.9078, 0.21444399999995767))'), points_table.geom)
The error reads
ERROR: function st_contains(geometry, geography) does not exist
LINE 1: SELECT * FROM points_table WHERE ST_Contains( ST_GEOMFRO...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
********** Error **********
ERROR: function st_contains(geometry, geography) does not exist
SQL state: 42883
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Character: 38
The answer from this question amongst others suggests my statement is correct.

Seems you are comparing GEOMETRY and GEOGRAPHY
As in your message error st_contains(geometry, geography)
be sure that your column points_table.geom is a valid GEOMETRY data type and not a GEOGRAPHY data type .. for this chek also for the SR you are using and eventually convert you geomtext as a valid SR for geography
eg assuming you using as SR 4326
SELECT *
FROM points_table
WHERE ST_Contains(
ST_Transform(
ST_GEOMFROMTEXT('POLYGON((51.8121, 0.13712199999997665, 51.9078, 0.21444399999995767))')
,4326)
, points_table.geom)

Although I accepted an answer that solved my statement, I feel it important to share an alternative to the explicit scenario (points within a boundary) as this is something I have struggled to find a solution to elsewhere.
SELECT * FROM points WHERE points.geom && ST_MakeEnvelope(0.13712199999997665, 51.8121, 0.26340800000002673, 51.9135, 4326)
This one is far simpler and yields the results exactly as required, same as the accepted answer.

I solved this problem by joining on public.ST_CONTAINS(geom, coords) instead of ST_CONTAINS(geom, coords)
I don't really understand enough about Postgresql to know why this worked though. I just skimmed https://gis.stackexchange.com/questions/132103/postgis-st-within-does-not-exist and hoped for the best.

Related

Postgres, query error: ERROR: operator does not exist: character varying = bigint?

I am trying to run this query:
select *
from my_table
where column_one=${myValue}
I get the following error in Datagrip:
[42883] ERROR: operator does not exist: character varying = bigint Hint: No operator matches the given name and argument types. You might need to add explicit type casts.
Now, I have found this question, and I can fix the error by putting a string like this:
select *
from my_table
where column_one='123'
What I need is a way to pass in the '123' as a parameter. I usually do this ${myValue} and it works, but I am not sure how to keep my variable there as an input so I can run dynamic queries in code and let Postgres understand I want to pass in a string and not a number.
Any suggestions?
Here's a screenshot of how I am putting the parameter value in DataGrip...:
Ok, so, I just tried to put quotes in the data grip parameters input field for myValue #thirumal's answer things work. I didn't know I have to quote the value for it to work.
This is what it looks like:
Type cast ${myValue} using SQL Standard,
cast(${myValue} AS varchar)
or using Postgres Syntax:
${myValue}::varchar

How to use Postgresql ts_delete function

I am trying to use Postgresql Full Text Search. I read that the stop words (words ignored for indexing) are implemented via dictionary. But I would like to give the user a limited control over the stop words (insert new ones), so I grouped then in a table.
From the example below:
select strip(to_tsvector('simple', texto)) from longtxts where id = 23;
I can get the vector:
{'alta' 'aluno' 'cada' 'do' 'em' 'leia' 'livro' 'pedir' 'que' 'trecho' 'um' 'voz'}
And now I would like to remove the elements from the stopwords table:
select array(select palavra_proibida from stopwords);
That returns the array:
{a,as,ao,aos,com,default,e,eu,o,os,da,das,de,do,dos,em,lhe,na,nao,nas,no,nos,ou,por,para,pra,que,sem,se,um,uma}
Then, following documentation:
ts_delete(vector tsvector, lexemes text[]) tsvector remove any occurrence of lexemes in lexemes from vector ts_delete('fat:2,4 cat:3 rat:5A'::tsvector, ARRAY['fat','rat'])
I tried a lot. For example:
select ts_delete((select strip(to_tsvector('simple', texto)) from longtxts where id = 23), array[(select palavra_proibida from stopwords)]);
But I always receive the error:
ERROR: function ts_delete(tsvector, character varying[]) does not exist
LINE 1: select ts_delete((select strip(to_tsvector('simple', texto))...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
Could anyone help me? Thanks in advance!
ts_delete was introduced in PostgreSQL 9.6. Based on the error message, you're using an earlier version. You may try select version(); to be sure.
When you land on the PostgreSQL online documentation with a web search, it may correspond to any version. The version is in the URL and there's a "This page in another version" set of links at the top of each page to help switching to the equivalent doc for a different version.

postgresql - center - "No function matches the given name and argument types. You might need to add explicit type casts."

On Slackware 14.0 x86_64 with postgresql-9.2.4 and postgis-2.0.3.
Have loaded essex-latest.osm.pbf into a database.
I want to get the centre of the roads in Essex, but am having problems.
These work OK:
SELECT st_Extent(way), st_area(st_Extent(way)) from planet_osm_roads;
st_extent | st_area
------------------------------------------------+------------------
BOX(-10979.62 6693910.54,144349.79 6822695.15) | 20004037488.3802
SELECT center(box '((-10979.62, 6693910.54),(144349.79, 6822695.15))');
center
-------------------------
(66685.085,6758302.845)
(But I have wondered why the function is center and not st_center).
Anyway, so why doesn't this work:
SELECT center(st_Extent(way)) from planet_osm_roads;
ERROR: function center(box2d) does not exist
LINE 1: SELECT center(st_Extent(way)) from planet_osm_roads;
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
Cheers,
Peter
Function center gets argument of type box, not box2d that st_Extent returns. With ST_Centroid you doesn't need to call st_Extent even, try ST_Centroid(way)
center is not a PostGIS function, it is a core geometry function for PostgreSQL.
The best way to find the midpoint of a linestring is to use a linear referencing function (e.g., ST_Line_Interpolate_Point() or ST_LineInterpolatePoint() for PostGIS >=2.1).
See also ST_PointOnSurface.

how to pass geometric point as parameter in postgres function?

I have some function where I need to pass a point datatype .
somefunc("United States",Point(85.327892 27.703744))
But I am getting error with this.
ERROR: syntax error at or near "27.703744"
SQL state: 42601
Character: 1192
Maybe try add a comma between the function params?
somefunc("United States",Point(85.327892, 27.703744))
I sense some confusion between PostGIS and PostgreSQL's geometric data types. If you are using PostGIS, you need the ST_MakePoint function, which is perfect for parameters:
SELECT ST_SetSRID(ST_MakePoint($lon, $lat), 4326)) AS geom;

What is wrong with this PostgreSQL statement?

I have the following statement that I need to run on a table which has a geometry column. I am getting a WKT from Oracle using my C# program and then attempting to insert it into PostgreSQL using an npgsql connection.
highways=# INSERT INTO cluster_125m (CELL_GEOM)
VALUES(ST_GeomFromWKT('POLYGON ((80000.0 17280.0, 80125.0 17280.0, 80125.0 17405.0, 80000.0 17405.0, 80000.0 17280.0))'));
I get the following error:
ERROR: function st_geomfromwkt(unknown) does not exist
LINE 1: INSERT INTO cluster_125m (CELL_GEOM) VALUES(ST_GeomFromWKT('...
^
HINT: No function matches the given name and argument types. You might need to
add explicit type casts.
What is the issue here and what can be done about it?
Use function ST_GeomFromText instead of ST_GeomFromWKT.