PostgresSQL FuzzySearch - postgresql

I am trying fuzzy search on PostgresSQL and have PostgreSQL 12.5 version installed.
After enabling extension:
CREATE EXTENSION pg_trgm with schema dev;
I am trying to execute below SQL
select * from dev.hello_world a where 'Hello' % ANY(STRING_TO_ARRAY(a.name, ' '))
SQL Error [42883]: ERROR: operator does not exist: unknown % text
Hint: No operator matches the given name and argument types. You might need to add explicit type casts.
I have tried this before and used to work. Not able to get reference from document for change.

Related

postgresql – No crypt function on Debian stretch

I have PostgreSQL 9.6 installation on my Debian Stretch (9). When I want to use crypt() or gen_salt() functions, it says:
ERROR: function gen_salt(unknown, integer) does not exist
LINE 1: select gen_salt('bf', 8)
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
How can I get these functions working?
Installed postgresql packages
You have to enable it using SQL:
CREATE EXTENSION IF NOT EXISTS pgcrypto;
You have to do it on each database that uses pgcrypto functions.

How to merge from SpatialLite to PostGIS?

How can I merge a SpatiaLite database to a PostGIS database?
I tried to use pgloader with the following command:
pgloader db.sqlite3 postgresql:///mydb
But it is not working. (I guess it is not supported). Please see the error output:
KABOOM!
FATAL error: Could not prepare an sqlite statement.
Code ERROR: no such module: VirtualSpatialIndex.
Database: /tmp/db.sqlite3
SQL: PRAGMA table_info(`SpatialIndex`)
An unhandled error condition has been signalled:
Could not prepare an sqlite statement.
Code ERROR: no such module: VirtualSpatialIndex.
Database: /tmp/db.sqlite3
SQL: PRAGMA table_info(`SpatialIndex`)
FATAL: Failed to start the monitor thread.
error opening #P"/tmp/pgloader/pgloader.log": Permission denied
I use in SpatialLite only the simple POINT field. Nothing else from SpatialLite. (With Lat/Lng values)
EDIT1:
#Corion
If I try to do your way I get no error doing this:
pgloader --before load_spatialite.sql db.sqlite3
But loading it to PostGIS with this command:
pgloader --before load_spatialite.sql db.sqlite3 postgresql:///mydb
gives me the following error message:
2018-10-10T11:29:16.056000Z ERROR Database error 42883: function load_extension(unknown) does not exist
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
QUERY: SELECT load_extension('mod_spatialite')
KABOOM!
FATAL error: Database error 42883: function load_extension(unknown) does not exist
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
QUERY: SELECT load_extension('mod_spatialite')
An unhandled error condition has been signalled:
Database error 42883: function load_extension(unknown) does not exist
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
QUERY: SELECT load_extension('mod_spatialite')
What I am doing here?
Database error 42883: function load_extension(unknown) does not exist
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
QUERY: SELECT load_extension('mod_spatialite')
What is here the problem?
SpatiaLite is an extension built into SQLite. You will need an SQLite binary / library that is built with SpatiaLite linked statically or load the SpatiaLite dynamic extension (see link) while importing.
From staring at the pgloader manpage, it seems that you can prepend SQL commands to load the SpatiaLite extension into SQLite like this:
pgloader --before load_spatialite.sql /tmp/db.sqlite3
and load_spatialite.sql contains
SELECT load_extension('mod_spatialite');
You may or may not need to set up additional environment variables such that dynamic libraries are found for your process.

function json_object_agg(text, bigint) does not exist postgres 9.2.4

Below Query are running in the local server postgress 9.6.6 but in the server postgres 9.2.4 ,below query is not working
select case_type,
(obj->> 'S')::int AS single,
(obj->> 'D')::int AS division,
(obj->> 'F')::int AS full
FROM (SELECT case_type, json_object_agg(bench,disposals) AS obj
FROM jws_ctype
GROUP BY case_type
)X
Error Below
ERROR: function json_object_agg(text, bigint) does not exist
LINE 5: FROM (SELECT case_type, json_object_agg(bench,disposals) AS ...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
********** Error **********
ERROR: function json_object_agg(text, bigint) 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: 133
json_object_agg was introduced in Postgres 9.4, that is why this query will not work in Postgres 9.2

Postgresql 9.5 Syntax error

I perform the same sql scripts on two server with different postgres versions. The first one has postgres 9.4.4 (this works fine) and the other one 9.5 (this throws an exception) installed.
UPDATE archived_invoice SET encrypted_xml
= encrypt(xml::bytea, 'MySuperSecretKey'::bytea, 'aes-ecb/pad:pkcs')
The exception:
Caused by: org.postgresql.util.PSQLException: ERROR: invalid input syntax for type bytea
SQL Status:22P02
Are there any differences between these two postgresql versions?
PostgreSQL will throw an ERROR: invalid input syntax for type bytea at you if the text you're casting into a bytea contains an invalid escape sequence:
# select '\i is not a valid escape sequence'::bytea;
ERROR: invalid input syntax for type bytea
LINE 1: select '\i is not a valid escape sequence'::bytea;
I'm guessing your "xml" column contains or may contain some backslashes. This is fine for XML and text columns, but presents an issue when casting to bytea.
You will need to escape the backslashes:
UPDATE archived_invoice SET encrypted_xml
= encrypt(
replace(xml, '\', '\\')::bytea,
'MySuperSecretKey'::bytea,
'aes-ecb/pad:pkcs'
)

IBM DB2 drop type error

I have a DB2 Db with this
create type mycar as(<br/>
description varchar(30)<br/>
)MODE DB2SQL;
how to delete that type?
I try drop type mycar, but have an error: DB2 for Linux, UNIX, and Windows: "DECLARE" was expected after ";".
Are you sure you have the ';' as command separator?
The Declare is just after the ';' which seems that your command separator is another, probably #.
For more information about dropping types:
Drop - http://pic.dhe.ibm.com/infocenter/db2luw/v10r5/topic/com.ibm.db2.luw.sql.ref.doc/doc/r0000945.html
Drop types - http://pic.dhe.ibm.com/infocenter/db2luw/v10r5/topic/com.ibm.db2.luw.admin.structypes.doc/doc/t0006611.html