How to install the cube function for Postgresql - postgresql

when I just run the sample statements like below:
select cube_union('(0,5,2),(2,3,1)', '0')
but facing the error:
postgres=# select cube_union('(0,5,2),(2,3,1)', '0');
ERROR: function cube_union(unknown, unknown) does not exist
LINE 1: select cube_union('(0,5,2),(2,3,1)', '0');
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
postgres=#
Can anyone help me? Is there any place I need to setup or need to install the function separately.

The cube_union() function is provided by the extension cube
To install an extension you need create extension
An extension is installed per database, so you need to connect to the database you are using as a super user, then run:
create extension cube;

Related

Why is earthdistance module not working in my Postgresql database?

I have a Postgresql (version 10) database, hosted on Amazon RDS. I was trying to experiment with the earthdistance module - everything I read says that the module should be available, but the server is acting like it doesn't exist.
=> select earth_distance(ll_to_earth(42.1, 19.1), ll_to_earth(42.2, 19.2));
ERROR: function ll_to_earth(numeric, numeric) does not exist
LINE 1: select earth_distance(ll_to_earth(42.1, 19.1), ll_to_earth(4...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
=> select ll_to_earth(42.1, 19.1) ;
ERROR: function ll_to_earth(numeric, numeric) does not exist
LINE 1: select ll_to_earth(42.1, 19.1) ;
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
=> select earth() ;
ERROR: function earth() does not exist
LINE 1: select earth() ;
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
I ran SHOW rds.extensions, and earthdistance does show up in the list. So what am I missing? Do I have to do something to activate this module?
You have to do create extension earthdistance in order to use it. Just because the binaries and scripts exist doesn't mean they are active.

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 : function set_config(unknown, bigint, boolean) doesn't exist

I am trying to use the current_setting() and set_config() functions for plpgpsq, to change the value of a custom setting I've added to my postgresql.conf file.
Here's what I added to the end of my postgresql.conf file :
IntegrityPackage.NestLevel = 0
After restarting the PostgreSQL service, here's what I get when I want to see the setting's value :
select current_setting('IntegrityPackage.NestLevel');
current_setting |
----------------|
0 |
However, when I try to edit the value, I get an error message :
select set_config('IntegrityPackage.NestLevel', 0, false);
ERROR: function set_config(unknown, bigint, boolean) doesn't exist.
Hint: No function corresponds to given name and argument types
You must add explicit type conversions
(Vaguely translated from french since the error message was in french)
There is very little documnetation about this, therefore I'm stuck and I can't think of another way to do this.
Edit - the exact error text (in psql 9.2 / postgresql 10.0) is:
ERROR: function set_config(unknown, integer, boolean) does not exist
LINE 1: select set_config('my.foo',obj_id::int ,false) from objects ...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
This will work:
select set_config('IntegrityPackage.NestLevel', '0', false);

I can create a stored procure with invalid user defined function names in it

I just noticed that I could alter my stored procedure code with a misspelled user defined function in it.
I noticed that at 1st time I execute the SP.
Is there any way to get a compile error when an SP include an invalid user-defined function name in it?
At compile time? No.
You can, however, use some of SQL's dependency objects (if using MS SQL) to find problems just after deployment, or as part of your beta testing. Aaron Bertran has a pretty nice article rounding up the options, depending upon the version of SQL Server.
Here is an example using SQL Server 2008 sys object called sql_expression_dependencies
CREATE FUNCTION dbo.scalarTest
(
#input1 INT,
#input2 INT
)
RETURNS INT
AS
BEGIN
-- Declare the return variable here
DECLARE #ResultVar int
-- Add the T-SQL statements to compute the return value here
SELECT #ResultVar = #input1 * #input2
-- Return the result of the function
RETURN #ResultVar
END
GO
--Fn Works!
SELECT dbo.ScalarTest(2,2)
GO
CREATE PROCEDURE dbo.procTest
AS
BEGIN
SELECT TOP 1 dbo.scalarTest(3, 3) as procResult
FROM sys.objects
END
GO
--Sproc Works!
EXEC dbo.procTest
GO
--Remove a dependency needed by our sproc
DROP FUNCTION dbo.scalarTest
GO
--Does anything have a broken dependency? YES
SELECT OBJECT_NAME(referencing_id) AS referencing_entity_name,
referenced_entity_name, *
FROM sys.sql_expression_dependencies
WHERE referenced_id IS NULL --dependency is missing
GO
--Does it work? No
EXEC dbo.procTest
GO

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.