convert output of postgres query to utf8 - postgresql

I used postgresql
in my attachment table the filename_attachmnt column contains character with wrong format .
for example it contains : تكلي٠الزميل. احمدالوردي.pdf
the correct name it should be this : تكليف الزميل. احمدالوردي.pdf
I try without success using this query :
select encode(convert(cast(filename_attachmnt as bytea),'UTF8'),'escape') from attachment
updated :
this is the config of my database :
CREATE DATABASE "mobiltyDatabase"
WITH OWNER = postgres
ENCODING = 'SQL_ASCII'
TABLESPACE = pg_default
LC_COLLATE = 'C'
LC_CTYPE = 'C'
CONNECTION LIMIT = -1;
GRANT CONNECT, TEMPORARY ON DATABASE "mobiltyDatabase" TO public;
GRANT ALL ON DATABASE "mobiltyDatabase" TO postgres;

Related

How create Oracle procedure witch select with dblink from postgres

I can select(in Oracle) from postgers with dblink, and its work fine.
But if i create procedure with this select:
Procedure:
`CREATE OR REPLACE PROCEDURE test_merge as
begin
MERGE INTO CARDS C
USING (SELECT c."card_id", 1, n."channel"
FROM "table_1"#DBLINK_NAME n
JOIN
"table_2"#DBLINK_NAME c
ON n."card_id" = c."id"
WHERE n."type" = 'param1') B
ON (C.CARDID = B."card_id")
WHEN MATCHED
THEN
UPDATE SET C.SENDR = 1, C.PHONE = '+' || B."channel";
end;`
ORA-04052: error occurred when looking up remote object postgres.table_name#DBLINK_NAME ORA-00604: error occurred at recursive SQL level 1 ORA-28500: connection from ORACLE to a non-Oracle system return this message: ERROR: relation "postgres.card" does
Have any idea?
Oracle 11g
Thanks!
It was necessary to specify the owner of the database on postgre. In my case, it was enough to specify "public". in the procedure. before accessing tables.
"public"."table_1"#DBLINK_NAME

How to convert UTF8 data from PostgreSQL to AL32UTF8 Oracle DB?

I have a task to import some data from Postgres database to Oracle via dblink
The connection between Postgres and Oracle works good, but unfortunately, when I try read data from created view (in Oracle database), I spotted a problem with data encoding - special national characters (Polish).
Source Postgres database have a UTF8 encoding, but Oracle have a AL32UTF8
Postgres:
select server_encoding
-
UTF8
Oracle:
select * from v$nls_parameters where parameter like '%CHARACTERSET';
-
PARAMETER VALUE
NLS_CHARACTERSET AL32UTF8
NLS_NCHAR_CHARACTERSET AL16UTF16
When I use command "isql -v" (on destination machine with Oracle database) and later "select * from table;", everything works good, but when I use this same select from Oracle database using dblink my data encoding is broken
For example:
from odbc:
isql -v
select * from table;
[ID][Name]
0,Warszawa
1,Kraków
2,Gdańsk
from oracle using dblink:
select * from table#dblink;
[ID][Name]
0,Warszawa
1,KrakĂłw
2,Gdańsk
/etd/odbc.ini:
[ODBC Data Sources]
[Postgres_DB]
Description = Postgres_DB
Driver = /usr/lib64/psqlodbcw.so
DSN = Postgres_DB
Trace = Yes
TraceFile = /tmp/odbc_sql_postgresdb.log
Database = database
Servername = server
UserName = user
Password = secret
Port = 5432
Protocol = 8.4
ReadOnly = Yes
RowVersioning = No
ShowSystemTables = No
ShowOidColumn = No
FakeOidIndex = No
SSLmode = require
Charset = UTF8
$ORACLE_HOME/hs/admin/initPostgres_DB.ora:
HS_FDS_CONNECT_INFO = Postgres_DB
HS_FDS_TRACE_LEVEL=DEBUG
HS_FDS_SHAREABLE_NAME = /usr/lib64/libodbc.so
HS_FDS_SUPPORT_STATISTICS = FALSE
HS_LANGUAGE=AL32UTF8
set ODBCINI=/etc/odbc.ini
I have installed these packages:
postgresql-libs.x8664 - 8.4.20-8.el69
postgresql-odbc.x8664 - 08.04.0200-1.el6
unixODBC.x8664 - 2.2.14-14.el6
unixODBC-devel.x86_64 - 2.2.14-14.el6
Please help me.. I need to have the correct data in Oracle..
Thank you very much

Granting permission in Postgresql to user never gives permission

I'm trying to give access to a database to a new user in PostgreSQL 10.12. For context, I'm using Ubuntu 18.04. I created the database with this code:
CREATE DATABASE jiradb WITH ENCODING 'UNICODE' LC_COLLATE 'C' LC_CTYPE 'C' TEMPLATE template0;
The user was given access with this code:
GRANT ALL PRIVILEGES ON DATABASE
Whenever I type "\z", all I see is this:
Access privileges
Schema | Name | Type | Access privileges | Column privileges | Policies
--------+------+------+-------------------+-------------------+----------
(0 rows)}
What I want to see is that this user "jiradbuser" has all access to the database "jiradb". I've checked PostgreSQL's web site, and nothing there has been helpful. How can I give this user the proper access?
The command
GRANT { { CREATE | CONNECT | TEMPORARY | TEMP } [, ...] | ALL [ PRIVILEGES ] }
ON DATABASE database_name [, ...]
TO role_specification [, ...] [ WITH GRANT OPTION ]
give access over the database with { CREATE | CONNECT | TEMPORARY | TEMP }
you will see the privileges with meta-command
\l
the meta-command
\z
Is to see privileges for tables view, sequences, in other words, are different types of objects (database and tables view, sequences)
you will see the tables view, sequences privileges given with the command
GRANT { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER }
[, ...] | ALL [ PRIVILEGES ] }
ON { [ TABLE ] table_name [, ...]
| ALL TABLES IN SCHEMA schema_name [, ...] }
TO role_specification [, ...] [ WITH GRANT OPTION ]
here you can use
\z

How to get data out of a postgres bytea column into a python variable using sqlalchemy?

I am working with the script below.
If I change the script so I avoid the bytea datatype, I can easily copy data from my postgres table into a python variable.
But if the data is in a bytea postgres column, I encounter a strange object called memory which confuses me.
Here is the script which I run against anaconda python 3.5.2:
# bytea.py
import sqlalchemy
# I should create a conn
db_s = 'postgres://dan:dan#127.0.0.1/dan'
conn = sqlalchemy.create_engine(db_s).connect()
sql_s = "drop table if exists dropme"
conn.execute(sql_s)
sql_s = "create table dropme(c1 bytea)"
conn.execute(sql_s)
sql_s = "insert into dropme(c1)values( cast('hello' AS bytea) );"
conn.execute(sql_s)
sql_s = "select c1 from dropme limit 1"
result = conn.execute(sql_s)
print(result)
# <sqlalchemy.engine.result.ResultProxy object at 0x7fcbccdade80>
for row in result:
print(row['c1'])
# <memory at 0x7f4c125a6c48>
How to get the data which is inside of memory at 0x7f4c125a6c48 ?
You can cast it use python bytes()
for row in result:
print(bytes(row['c1']))

Postgresql: why "ILIKE" is case-sensitive sometimes?

I'm searching this row:
"c717e4d6-8db3-4c68-8c6f-f853c6c62312", "Аристотель", "source"
These queries successfully finding it:
SELECT id, name, type FROM amt WHERE owner = '802f11da-c41c-4ad0-ae15-c7cf734c807f' AND name LIKE '%Ари%' limit 5;
SELECT id, name, type FROM amt WHERE owner = '802f11da-c41c-4ad0-ae15-c7cf734c807f' AND name ILIKE '%Ари%' limit 5;
This one does NOT finding it:
SELECT id, name, type FROM amt WHERE owner = '802f11da-c41c-4ad0-ae15-c7cf734c807f' AND name ILIKE '%ари%' limit 5;
As you see, the difference between 2nd and 3rd query is only one letter: "Ари" vs "ари".
Usually, ILIKE works as expected, but in some cases it just can't properly search. I have no idea why it happens.
SQL pane from current database:
CREATE DATABASE v_2_prod
WITH OWNER = postgres
ENCODING = 'UTF8'
TABLESPACE = pg_default
LC_COLLATE = 'C'
LC_CTYPE = 'C'
CONNECTION LIMIT = -1;