Flink postgres jdbc source connector read uppercase field failed

71 Views Asked by At

I am trying to use flink1.18 sql-client.sh to read pg data, but failed with uppercase field, named idLog.
I found that flink automatically converts uppercase fields to lowercase fields.
I try to work with ORACLE, Flink work success with uppercase field.

CREATE TABLE tmp_tb (
      `aa` string,
      `idLog` string
      ) WITH (
      'connector' = 'jdbc',
      'url' = 'jdbc:postgresql://vm131:5432/postgres',
      'username' = 'postgres',
      'password' = '123456',
      'table-name' = 'public.roamer'
);
Flink SQL> select `idLog` from tmp_tb;

error log

[ERROR] Could not execute SQL statement. Reason:
org.postgresql.util.PSQLException: ERROR: column "idlog" does not exist
  Hint: Perhaps you meant to reference the column "roamer.idLog".
  Position: 8
1

There are 1 best solutions below

0
On

Only double quoted identifiers are case sensitive in postgres.

From the docs:

Quoting an identifier also makes it case-sensitive, whereas unquoted names are always folded to lower case. For example, the identifiers FOO, foo, and "foo" are considered the same by PostgreSQL, but "Foo" and "FOO" are different from these three and each other.

Unfortunately, it looks like you hit a bug because you cannot use double quotes in FlinkSQL so this has to be fixed in the JDBC connector, see: FLINK-23324.