How to execute H2db generated statment in postgres - postgresql

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

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.

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

Can't save double precision[] in PgAdmin

I am quite new to PostgreSQL and pgadmin. I have created a table named "indication" with one double precision [] column. Whenever I attempt to save any double precision array data (typed here as "{23.2, 25.1}", pgadmin gives me the following error:
ERROR: operator does not exist: double precision[] = text[] LINE 3: "Size" = ARRAY['23.2','25.1'] HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
I'm not sure what to do here. I can use command line PSQL if necessary, but I prefer to add data via GUI.
Here's a screenshot of my error:
Can you try updating using syntax like {23.2, 25.1}

ERROR: invalid input syntax for type numeric: "N/A" ... nice but which column?

I am running a function in PostgreSQL which contains several functions which purpose is to load data from foreign tables into mine. While running I get this error:
[SELECT - 0 row(s), 762.353 secs] [Error Code: 0, SQL State: 22P02] ERROR: invalid input syntax for type numeric: "N/A"
Where: PL/pgSQL function import_data_3(integer,timestamp with time zone,timestamp with time zone,integer) line 16 at SQL statement
SQL statement "SELECT import_data_3(import, beg, end_t, is_l)"
PL/pgSQL function data_import_all(timestamp with time zone,timestamp with time zone,integer,integer) line 31 at PERFORM
I know what that means and also its reason I am trying to convert 'N/A' string to number and there for this error, problem is this lousy error does not specify the column where the error occurred.
Is there a way to get more precise error message which would tell me the exact column where the error happened?
It's not in the column but in one of the parameters that are passed to import_data_3.
You called the query SELECT import_data_3(import, beg, end_t, is_l).
The specification of this function is import_data_3(integer,timestamp with time zone,timestamp with time zone,integer)
Since you got the error
invalid input syntax for type numeric: "N/A"
this most likely means that either first parameter "import" or the last one "is_l" contain the value "N/A". Try to debug the calling code of the function data_import_all and see how those two parameter values are generated.

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.