[ 
https://issues.apache.org/jira/browse/FLINK-18640?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17541275#comment-17541275
 ] 

Yaroslav Tkachenko commented on FLINK-18640:
--------------------------------------------

I'd love to address this issue, because currently, PostgresDialect is not very 
useful in real production scenarios, e.g. keywords used as column names are 
quite common.

I want to propose a simple and elegant (in my opinion) change to address the 
issue (I can create a PR if we agree here):
{code:java}
public String quoteIdentifier(String identifier) {
    // skip if already quoted
    if (identifier.startsWith("\"")) {
        return identifier;
    } else {
        return "\"" + identifier + "\"";
    }
} {code}
Why I consider it the best solution:
 * It's very simple, minimum changes.
 * Since Postgres identifiers can have dots, it's very hard to understand when 
it's safe to split them for escaping. E.g., schema.table_name is fine to escape 
like "schema"."table_name", but you can't do the same for schema.table.name. 
So, my proposal - just let the user deal with it. They know how to escape 
properly. That's why _quoteIdentifier_ checks for quoting first.
 * In most of the scenarios though, identifiers won't have dots, so it's safe 
to quote them.

Thoughts?

> Fix PostgresDialect doesn't quote the identifiers
> -------------------------------------------------
>
>                 Key: FLINK-18640
>                 URL: https://issues.apache.org/jira/browse/FLINK-18640
>             Project: Flink
>          Issue Type: Bug
>          Components: Connectors / JDBC, Table SQL / Ecosystem
>    Affects Versions: 1.9.1, 1.10.1
>            Reporter: 毛宗良
>            Priority: Not a Priority
>              Labels: auto-deprioritized-major, auto-deprioritized-minor, 
> pull-request-available
>
> Flink jdbc throw exceptions when read a postgresql table with scheam, like 
> "ods.t_test". BY debugging the source code, I found a bug about dealing the 
> table name.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to