pg_trgm in Amazon RDS - postgresql

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?

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.

i am failing to do geoserver conncetion to postgis

Error creating data store, check the parameters. Error message: Unable to obtain connection: ERROR: function postgis_lib_version() does not exist Hint: No function matches the given name and argument types. You might need to add explicit type casts. Position: 8

Is "create domain" allowed with a base type of json (or jsonb)?

I have a custom type with code similar to the following (shortened for brevity):
create domain massFraction as jsonb (
value->'h' > 0 and value->'h' is not null
);
Running this provokes the following error:
ERROR: type modifier is not allowed for type "jsonb"
The documentation makes no mention of json being a disallowed base type for a domain.
https://www.postgresql.org/docs/12/sql-createdomain.html
I also thought that it was perhaps the "not null" part of the constraint, which the documentation mentions is "tricky". Additionally, I've tried similar statements without any json operators. All of these seem to be disallowed.
I am obnoxiously prone to not reading documentation, and worse still about understanding documentation when I do bother to read it... so does it not exist, or am I looking in the wrong places to see if this is permitted? Why is it not permitted?
You're missing a CHECK after jsonb:
create domain massFraction as jsonb check (
value->'h' > 0 and value->'h' is not null
);
This results in another error:
ERROR: 42883: operator does not exist: jsonb > integer
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
I believe what you want is
CREATE DOMAIN massFraction AS jsonb CHECK (
CASE jsonb_typeof(value->'h')
-- only cast when it is safe to do so
-- note: this will reject numeric values stored as text in the json object (eg '{"h": "1"}')
WHEN 'number' THEN (value->>'h')::integer > 0
ELSE false
END
)
The error you're getting comes from the fact that you input is parsed as
CREATE DOMAIN massFraction AS jsonb(<modifier>) -- like in varchar(10)
As an aside I would recommend against using camelCase in postgresql, as massFraction is the same as massfraction (unless quoted) and postgresql will use the lowercased form when reporting errors, hints, etc.

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

How to execute H2db generated statment in postgres

Below statmen generated from h2
INSERT INTO EPSG_ALIAS
(ALIAS_CODE, OBJECT_TABLE_NAME, OBJECT_CODE, NAMING_SYSTEM_CODE, ALIAS, REMARKS)
VALUES
(1431, 'Datum', 6123, 7300, STRINGDECODE('Kartastokoordinaattij\ufffdrjestelm\ufffd (1966)'), NULL);
When i execute the above statment in postgresql i am getting following error.
ERROR: function stringdecode(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.
Character: 140
STRINGDECODE is the way of H2 to read 'ASCII written UTF-8 characters'.
For Postgres, it's a simple 'E' before your string:
STRINGDECODE('Kartastokoordinaattij\ufffdrjestelm\ufffd (1966)')
Becomes
E'Kartastokoordinaattij\ufffdrjestelm\ufffd (1966)'