Proc SQL to Postgres UFT8 database: non printable character shown as normal question mark, can't remove - postgresql

I need advice for a problem I'm facing:
I use SAS 9.4 (desktop version) to connect to a Postgres database with the Unicode Postgres ODBC driver.
I'm using a proc sql statement to retrieve the data and create a sas data file.
There is one issue:
One entry has the following value in the database it PgAdmin: "CAR "
But when I look at the SAS data file that proc sql created it looks like this: "CAR ?"
Just a normal question mark.
The compress function with _FIELD = compress(_FIELD, ,'kw'); doesn't seem to work, as the question mark is just a normal question mark and not a non printable character.
Postgres database has UTF8 as server encoding.
The ODBC connection uses Unicode Postgres drivers.
I tried running SAS with the English (creates a Wlatin1 dataset) and Unicode option (creates a UTF8 dataset) but nothing changes.
I would like to be able to remove this character.
Any tips or suggestions would be helpful.
Thanks!

Related

Clob(length 1048576) DB2 to PostgreSQL best datatype?

We had a table with a column with a Clob(length 1048576) that would store search text that helps with searching. When I transferred it from DB2 to Postgres in our migration, I found that it wasn't working as well. So I going to try text or varchar, but I was finding it would take much longer for the long text entries to be added to the table to the point my local wildfly window would timeout when trying to run.
What is the equilavelent of a datatpye that accepts text that I should be using in postgres to replace a Clob that was length 1048576 in DB2? It might be that I was using the right datatypes but didn't have the right corresponding size.
Use text. That is the only reasonable data type for long character strings.

\copy in is unable to fit utf-8 into varying(30)

In order to build the staging database from my production data to test migrations, etc. I do a regular \copy of a subset of production records to CSV files, and import the result. I do this for the specific tables with are very large (600G), as I don't need them all for testing.
One such column is a varying(30) [for hysterical raisins involving django 1].
I have data in that column which is UTF-8 encoded. Some of it is exactly 30 glyphs wide. But, that takes more than 30 bytes to encode. Strangely, it fits just fine in the original database, but after creating a new database, it does not fit.
I copy in with:
\copy public.cdrviewer_cdr from '/sg1/backups/2017-02-20/cdr.csv'
with (format 'csv', header, encoding 'utf-8') ;
This seems like it may be a bug, or maybe it's just a limitation of copy.
(I am using postgresql 9.6 on Devuan Jessie)

How to change Oracle 10gr2 express edition's default character set

I installed oracle 10gr2 express edition on my laptop.
when I import a .dmp file which is generated by oracle 10gr2 enterprise edition, error occurs.
the database server which generated the .dmp file is running with GBK charset, but my oracle express server is running with UTF-8.
SQL> select userenv('language') from dual;
USERENV('LANGUAGE')
--------------------------------------------------------------------------------
SIMPLIFIED CHINESE_CHINA.AL32UTF8
how can I configure my own oracle server to import the .dmp file?
edit ---------------------------------------------------
my own oracle express server:
SQL> select * from v$nls_parameters where parameter like '%CHARACTERSET';
PARAMETER
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
NLS_CHARACTERSET
AL32UTF8
NLS_NCHAR_CHARACTERSET
AL16UTF16
The new character set requires up to 4 bytes per character while the old one only required up to 2 bytes. So due to the character set change, some character fields will require more space than before. Obviously, some of them have now hit the column lenght limit.
To resolve it, you'll have to increase the length of the affected columns or change the length semantics so the length is interpreted in characters (and not in bytes, which is the default).
If your dump file contains both the schema definition and the data, you'll have to work in phases: first import the schema only, the increase the column lengths and finally import the data.
I have no experience with the length semantics. I usually specify it explicit. See the documentation about the NLS_LENGTH_SEMANTICS parameter for information. It affects how the number 100 in the following statement is interpreted:
CREATE TABLE example (
id NUMBER,
name VARCHAR(100)
);
Usually, it's better to be explicit and specify the unit directly:
CREATE TABLE example (
id NUMBER,
name VARCHAR(100 CHAR)
);
The dump file contains a whole schema, alter column length is not a good option for me.
the Oracle Express edition use UTF-8 as default, after googled the web, I found a way to alter the database character set.
in my case:
UTF-8 --> GBK
I connected with user sys as sysdba in sqlplus. then executed following commands:
shutdown immediate
startup mount
alter system enable restricted session ;
alter system set JOB_QUEUE_PROCESSES=0;
alter system set AQ_TM_PROCESSES=0;
alter database open;
alter database character set internal_use ZHS16GBK ;
shutdown immediate
startup
I don't know what these commands done to my database, but It works.

How to get and change encoding schema for a DB2 z/OS database using dynamic SQL statement

A DB2 for z/OS database has been setup for me. Now I want to know the encoding scheme of the database and change it to Unicode if the database is other type of encoding.
How can I do this? Can I do this using dynamic SQL statements in my Java application?
Thanks!
You need to specify that the encoding scheme is UNICODE when you are creating your table (and database and tablepsace) by using the CCSID UNICODE clause.
According to the documentation:
By default, the encoding scheme of a table is the same as the encoding scheme of its table space. Also by default, the encoding scheme of the table space is the same as the encoding scheme of its database. You can override the encoding scheme with the CCSID clause in the CREATE TABLESPACE or CREATE TABLE statement. However, all tables within a table space must have the same CCSID.
For more, see Creating a Unicode Table in the DB2 for z/os documentation.
You are able to create tables via Java/JDBC, but I doubt that you will be able to create databases and tablespaces that way. I wouldn't recommend it anyway, I would find your closest z/os DBA and get that person to help you.

Transferring data from one database to another (Postgres)

I have 2 exactly same databases on 2 different machines(with different data that is), and I want to transfer contents of one table to the table from the other database, how do I do that from PgAdmin? I'm new to PostgreSQL Database, I'd do that easily with mysql phpmyadmin just export sql and I'd get text file with bunch of insert into statements, is there equivalent with PgAdmin ?
Yes, backup using "PLAIN" format (SQL statements) and then (when connected to the other DB) open the file and run it.
Or you could select "COMPRESS" format in the "backup" dialogue, and then you could use the restore dialogue.
Also there's an equivalent of phpMyAdmin for Postgres, called "phppgadmin". Select the table in question and then use the "Export" tab.
pg_dump from the command line