alibaba / alibaba/DataX

postgresql writer bug

Open
#1,928 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
17.4k
Forks
5.7k
PR merge metrics
No merged PRs in 30d

Description

在PostgreSQLwriter中,如果表的数据类型是char(2),那么在导数据的时候,会将数据强制转成char,而不带长度的char默认长度为1,导致数据被截断丢失。

举例:
INSERT INTO t_table (col) values('01':char);

在数据库查询时发现该表字段对应的列数据为'0 ',而不是'01',正确做法是需要将'01'转成varchar或者char(2);
如:
INSERT INTO t_table (col) values('01':char(2));
INSERT INTO t_table (col) values('01':varchar);

见代码:postgresqlwriter/src/main/java/com/alibaba/datax/plugin/writer/postgresqlwriter/PostgresqlWriter.java 75行

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at postgresqlwriter/src/main/java/com/alibaba/datax/plugin/writer/postgresqlwriter/PostgresqlWriter.java around line 75 and inspect how values are cast for PostgreSQL inserts. Reproduce the case with a char(2) column and the value '01'; done means the stored value remains '01' instead of being truncated, using the appropriate cast described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, postgresql
Domain
databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.