Why is earthdistance module not working in my Postgresql database? - postgresql

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.

Related

Passing a row type to jsonb_to_recordset syntax errors

I'm trying to work out how to expand a JSONB field with a jsonb_to_recordset and a custom type.
Postgres 11.4.
This is just a test case, but for the minute I'm trying to work out the syntax. I've got a table named data_file_info with a JSONB field named table_stats. The JSONB field always includes a JSON array with the same structure:
[
{"table_name":"Activity","record_count":0,"table_number":214},
{"table_name":"Assembly","record_count":1,"table_number":15},
{"table_name":"AssemblyProds","record_count":0,"table_number":154}
]
The following code works correctly:
from data_file_info,
jsonb_to_recordset(table_stats) as table_stats_splat (
table_name text,
record_count integer,
table_number integer
)
What I would like to do is pass in a custm type definition instead of the long-form column definition list shown above. Here's the matching type:
create type data.table_stats_type as (
table_name text,
record_count integer,
table_number integer)
Some examples I've seen, and the docs say, that you can supply a type name using a null:row_type casting in the first parameter to jsonb_to_recordset. The examples that I've found use in-line JSON, while I'm trying to pull stored JSON. I've made a few attempts, all have failed. Below are two of the trials, with errors. Can someone point me towards the correct syntax?
FAIL:
select table_stats_splat.*
from data_file_info,
jsonb_populate_recordset(null::table_stats_type, data_file_info) as table_stats_splat;
-- ERROR: function jsonb_populate_recordset(table_stats_type, data_file_info) does not exist
-- LINE 4: jsonb_populate_recordset(null::table_stats_type, dat...
^
-- HINT: No function matches the given name and argument types. You might need to add explicit type casts. (Line 4)
FAIL:
select *
from jsonb_populate_recordset(NULL::table_stats_type, (select table_stats from data_file_info)) as table_stats_splat;
-- ERROR: more than one row returned by a subquery used as an expression. (Line 2)
I'm doubtlessly missing something pretty obvious, and am hoping someone can suggest what that is.
Use the column as the second parameter:
select table_stats_splat.*
from data_file_info,
jsonb_populate_recordset(null::table_stats_type, table_stats) as table_stats_splat;

How to install the cube function for 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;

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);

pg_trgm in Amazon RDS

pg_trgm is supported according to Amazon's docs, but my search scope is no longer working after a switch from Heroku's postgres to Amazon.
pg_search_scope :trigram_search, :against => [:first_name, :last_name], :using => {:trigram => {:threshold => 0.5}}
Now I get the following error:
ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR: function similarity(text, unknown) does not exist
LINE 1: ...is' || ' ''')), 0)) AS rank FROM "people" WHERE ((similarity...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
Do I need to do something extra to enable the trigram extension?

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.