Can't use pgRouting functions in PostgreSQL 9.2 - postgresql

I have 3 pgRouting sql files,
routing_core
routing_core_wrappers
routing_topology
And I run the code in the first one in PostgreSQL 9.2, I got this error,
PS. although there are already pgRouting functions in extensions of 9.2, I still can't run the following code,
ALTER TABLE tc_2000_w_area ADD COLUMN source integer;
ALTER TABLE tc_2000_w_area ADD COLUMN target integer;
SELECT assign_vertex_id('tc_2000_w_area', 0.0001, 'the_geom', 'gid')
got the error,
>>>
Traceback (most recent call last):
File "C:/Users/Heinz/Desktop/python_test/any_test.py", line 12, in <module>
cur.execute(query)
ProgrammingError: 錯誤: 函式 assign_vertex_id(unknown, numeric, unknown, unknown) 不存在
LINE 4: SELECT assign_vertex_id('tc_2000_w_area', 0.0001, 'the_g...
^
HINT: 沒有符合指定之名稱和參數型別的函式。您可能需要加入明確型別轉換。
So I think to run the above 3 sql files first.
But I can run all 3 sql files in PostgreSQL 8.4
I am working with PostgreSQL 9.2, PostgreSQL 8.4 under Windows 8.1 x64.
UPDATE#1
I run the code below, but shows error message,
create extension pgrouting;
錯誤: 擴充功能 "pgrouting" 已存在
********** 錯誤 **********
錯誤: 擴充功能 "pgrouting" 已存在
SQL 狀態: 42710
the error message means the pgRouting extension already exists, but if I directly use the code in my original post, got the same error as I posted.

You have to install postgis before pgrouting.
create extension postgis;
create extension pgrouting;
Then you should be able to use it.

Related

Error while try to connect table on DB2 using Python (SQL0332N)

I'm connecting to DB2-LUW database using Python 3.7 and some queries get error : "SQL0332N Character conversion from the source code page "1252" to the target code page "874" is not supported.***".
First I try to test the connection of Python to the database on DB2 by recreating a new table.
I insert 1 record and read it back. When I read the inserted row, I get the error.
Results in interactive python:
import ibm_db_dbi as dbi
print(dbi.__version__)
3.0.2
conn = dbi.connect("DATABASE=<db>;HOSTNAME=<hostname>;PORT=<port>;PROTOCOL=TCPIP;UID=<user>;PWD=<pwd>;", "", "")
c = conn.cursor()
c.execute('create table ibm_db_tst (col1 int)')
Out[5]: True
c.execute('insert into ibm_db_tst values(2)')
Out[6]: True
c.execute('select col1 from ibm_db_tst')
Out[7]: True
print(c.fetchone())
Traceback (most recent call last):
File "C:\Users\2400566\Anaconda3\lib\site-packages\ibm_db_dbi.py",
line 1449, in _fetch_helper
row = ibm_db.fetch_tuple(self.stmt_handler)
SQLCODE=-332lumn information cannot be retrieved: [IBM][CLI
Driver][DB2/NT64] SQL0332N Character conversion from the source code
page "1252" to the target code page "874" is not supported.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
print(c.fetchone())
File "C:\Users\2400566\Anaconda3\lib\site-packages\ibm_db_dbi.py", line 1475, in fetchone
row_list = self._fetch_helper(1)
File "C:\Users\2400566\Anaconda3\lib\site-packages\ibm_db_dbi.py", line 1456, in _fetch_helper
raise self.messages[len(self.messages) - 1]
SQLCODE=-332_dbi::Error: [IBM][CLI Driver][DB2/NT64] SQL0332N Character conversion from the source code page "1252" to the target code page "874" is not supported.
I'm not sure what's wrong? Need advice.
my Python version is Python 3.7.7 running on Window 10 PC x64
DB2 is on Windows server 2012 x64 .
DB2 version is DB2 v11.1.0.1527.
Database territory : GB
Database code page : 1252
Database code set : 1252
Database country/region code : 44
Thanks in advance.
In case that your python script is using db2dsdriver to connect to database on server, try to set the DisableUnicode keyword to 0 to enforce unicode code page (i.e. 1208) on Windows.
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.swg.im.dbclient.config.doc/doc/r0054636.html

bucardo sync issue, function does not exist

I have issues with adding database to sync. DB versions: PostgreSQL 9.6.8 (RDS), Jump system: Ubuntu18.04 LTS, bucardo version: 5.4.1.
When trying run this command:
bucardo add sync db_sync relgroup=copying_herd dbs=source_db:source,dest_db:target onetimecopy=1
I receive this error:
WARNING: Issuing rollback() due to DESTROY without explicit disconnect() of DBD::Pg::db handle dbname=dc_sourcedb;host=xxx.aaa.xyz;port=5432 at line 126.
Failed to add sync: DBD::Pg::st execute failed: ERROR: DBD::Pg::db do failed: ERROR: function search_string(text) does not exist
LINE 5: array_agg(search_string(x)),
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
QUERY:
SELECT
coalesce(
array_to_string(
array_agg(search_string(x)),
'|'
)::text,
''
)
FROM unnest($1) x
CONTEXT: SQL function "flatten_text_array" during inlining at line 126. at line 30.
CONTEXT: PL/Perl function "validate_sync" at /usr/bin/bucardo line 4612.
Function search_string exist and I can run this function from psql command line

BigSQL PostgreSQL CREATE EXTENSION errors

I have windows 8.1 and I want to try hadoop_fdw. Problem is with loading the extension with:
CREATE EXTENSION hadoop_fdw;
ddssdg
ERROR: could not load library "D:/PROGRA~2/POSTGR~2/pg95/../pg95/lib/postgresql/hadoop_fdw.dll": unknown error 126
********** Error **********
ERROR: could not load library "D:/PROGRA~2/POSTGR~2/pg95/../pg95/lib/postgresql/hadoop_fdw.dll": unknown error 126
SQL state: XX000
I tried to create extension manually from SQL located at "D:\Program Files\PostgreSQLBigsql\pg95\share\postgresql\extension"
CREATE FUNCTION hadoop_fdw_handler()
RETURNS fdw_handler
AS 'D:\Program Files\PostgreSQLBigsql\pg95\lib\postgresql\hadoop_fdw.dll'
LANGUAGE C STRICT;
CREATE FUNCTION hadoop_fdw_validator(text[], oid)
RETURNS void
AS 'D:\Program Files\PostgreSQLBigsql\pg95\lib\postgresql\hadoop_fdw.dll'
LANGUAGE C STRICT;
CREATE FOREIGN DATA WRAPPER hadoop_fdw
HANDLER hadoop_fdw_handler
VALIDATOR hadoop_fdw_validator;
I get this error same error again:
ERROR: could not load library "D:\Program Files\PostgreSQLBigsql\pg95\lib\postgresql\hadoop_fdw.dll": unknown error 126
********** Error **********
ERROR: could not load library "D:\Program Files\PostgreSQLBigsql\pg95\lib\postgresql\hadoop_fdw.dll": unknown error 126
SQL state: XX000
What I am doing wrong?
EDIT 1: So I found missing DLL's. They are:
API-MS-WIN-CORE-KERNEL32-PRIVATE-L1-1-1.DLL
API-MS-WIN-CORE-PRIVATEPROFILE-L1-1-1.DLL
API-MS-WIN-SERVICE-PRIVATE-L1-1-1.DLL
JVM.DLL
I added them to C:\Windows\SysWOW64\ and extension still doesn't work - it probably requires restart.

Running Spatial Queries in PostGIS 2.1.3 and Postgresql 9.3 in Windows 7

I installed PostGreSql 9.3 ( PgAdmin 3 GUI) and PostGIS 2.1.3 (http://www.enterprisedb.com/products-services-training/pgdownload#windows) for Windows 7 64 bit.
After installing it, I downloaded the Sql files for country database (http://www.spatial.cs.umn.edu/Book/labs/vania/spatialQueries.html) and tried to execute the commands in Country.sql
in the Sql Builder and stuck at the following error:
NOTICE: SRID value -1 converted to the officially unknown SRID value 0
CONTEXT: SQL statement "SELECT AddGeometryColumn('',$1,$2,$3,$4,$5,$6,$7)"
PL/pgSQL function addgeometrycolumn(character varying,character varying,character varying,integer,character varying,integer,boolean) line 5 at SQL statement
ERROR: function geometryfromtext(unknown, integer) does not exist
LINE 4: ...3000.0000','Dollar','USD','N','5','United States',GeometryFr...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
********** Error **********
ERROR: function geometryfromtext(unknown, integer) 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: 769
I can't get this error resolved. Please help me out.

Is PostGIS 2 installed?

When I tried theh following command in psql:
select PostGIS_full_version();
I get the error:
ERROR: function postgis_full_version() does not exist
LINE 1: select PostGIS_full_version();
^
HINT: No function matches the given name and argument types.
You might need to add explicit type casts.
I have PostGIS 2 installed, yum list postgis*
Installed Packages
postgis2_91.i686 2.0.1-1.rhel6 #pgdg91
postgis2_91-devel.i686 2.0.1-1.rhel6 #pgdg91
Available Packages
postgis.i686 1.5.3-1.el6 epel
postgis-docs.i686 1.5.3-1.el6 epel
postgis-jdbc.i686 1.5.3-1.el6 epel
postgis-utils.i686 1.5.3-1.el6 epel
postgis2_91-debuginfo.i686 2.0.1-1.rhel6 pgdg91
postgis2_91-docs.i686 2.0.1-1.rhel6 pgdg91
postgis2_91-utils.i686 2.0.1-1.rhel6 pgdg91
postgis91.i686 1.5.5-1.rhel6 pgdg91
postgis91-debuginfo.i686 1.5.5-1.rhel6 pgdg91
postgis91-docs.i686 1.5.5-1.rhel6 pgdg91
postgis91-utils.i686 1.5.5-1.rhel6 pgdg91
Why does the command select PostGIS_full_version(); not work?
I tried the above because a script working with PostgreSQL and PostGIS had a problem finding PostGIS. It searches for
/usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql
which came from the line
pgsqlRunScriptFile(CONST_Path_Postgresql_Postgis.'/postgis.sql');
Why is it getting the wrong path, and how can I fix this?
Installing the software is just step one. You also have to enable it in the database you want it. For PostGIS 2, in the database you want to do spatial things, run
CREATE EXTENSION postgis;
as a super user. Magic should occur.