You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "jdAction (via GitHub)" <gi...@apache.org> on 2024/07/25 10:08:17 UTC
[I] How to set the default schema for PostgreSQL [shardingsphere]
jdAction opened a new issue, #32265:
URL: https://github.com/apache/shardingsphere/issues/32265
At present, I have manually implemented it using code, but this code is very smelly. Is there any other way to handle it,The code is as follows
```Java
public final class PostgreSQLDatabaseMetaData implements DialectDatabaseMetaData {
private static final Set<String> RESERVED_WORDS = new HashSet<>(Arrays.asList(
"ALL", "ANALYSE", "ANALYZE", "AND", "ANY", "ARRAY", "AS", "ASC", "ASYMMETRIC", "AUTHORIZATION", "BETWEEN", "BIGINT", "BINARY",
"BIT", "BOOLEAN", "BOTH", "CASE", "CAST", "CHAR", "CHARACTER", "CHECK", "COALESCE", "COLLATE", "COLLATION", "COLUMN", "CONCURRENTLY", "CONSTRAINT", "CREATE", "CROSS", "CURRENT_CATALOG",
"CURRENT_DATE", "CURRENT_ROLE", "CURRENT_SCHEMA", "CURRENT_TIME", "CURRENT_TIMESTAMP", "CURRENT_USER", "DEC", "DECIMAL", "DEFAULT", "DEFERRABLE", "DESC", "DISTINCT", "DO", "ELSE", "END",
"EXCEPT", "EXISTS", "EXTRACT", "FALSE", "FETCH", "FLOAT", "FOR", "FOREIGN", "FREEZE", "FROM", "FULL", "GRANT", "GREATEST", "GROUP", "GROUPING", "HAVING", "ILIKE", "IN", "INITIALLY",
"INNER", "INOUT", "INT", "INTEGER", "INTERSECT", "INTERVAL", "INTO", "IS", "ISNULL", "JOIN", "LATERAL", "LEADING", "LEAST", "LEFT", "LIKE", "LIMIT", "LOCALTIME", "LOCALTIMESTAMP",
"NATIONAL", "NATURAL", "NCHAR", "NONE", "NORMALIZE", "NOT", "NOTNULL", "NULL", "NULLIF", "NUMERIC", "OFFSET", "ON", "ONLY", "OR", "ORDER", "OUT", "OUTER", "OVERLAPS", "OVERLAY", "PLACING",
"POSITION", "PRECISION", "PRIMARY", "REAL", "REFERENCES", "RETURNING", "RIGHT", "ROW", "SELECT", "SESSION_USER", "SETOF", "SIMILAR", "SMALLINT", "SOME", "SUBSTRING", "SYMMETRIC", "TABLE",
"TABLESAMPLE", "THEN", "TIME", "TIMESTAMP", "TO", "TRAILING", "TREAT", "TRIM", "TRUE", "UNION", "UNIQUE", "USER", "USING", "VALUES", "VARCHAR", "VARIADIC", "VERBOSE", "WHEN", "WHERE",
"WINDOW", "WITH", "XMLATTRIBUTES", "XMLCONCAT", "XMLELEMENT", "XMLEXISTS", "XMLFOREST", "XMLNAMESPACES", "XMLPARSE", "XMLPI", "XMLROOT", "XMLSERIALIZE", "XMLTABLE"));
@Override
public QuoteCharacter getQuoteCharacter() {
return QuoteCharacter.QUOTE;
}
@Override
public NullsOrderType getDefaultNullsOrderType() {
return NullsOrderType.LAST;
}
@Override
public boolean isReservedWord(final String identifier) {
return RESERVED_WORDS.contains(identifier.toUpperCase());
}
@Override
public boolean isSchemaAvailable() {
return true;
}
@Override
public String getSchema(Connection connection) {
String schema = DialectDatabaseMetaData.super.getSchema(connection);
if (StrUtil.isBlank(schema)) {
schema = "public";
}
return schema;
}
@Override
public Optional<String> getDefaultSchema() {
String yamlFile = "classpath:config.yaml";
String yamlContent = FileUtil.readUtf8String(yamlFile);
Yaml yaml = new Yaml(new ShardingSphereYamlConstructor(YamlJDBCConfiguration.class));
YamlJDBCConfiguration jdbcConfiguration = yaml.load(yamlContent);
String url = (String) jdbcConfiguration.getDataSources().get("ds_0").get("url");
JdbcUrl jdbcUrl = new StandardJdbcUrlParser().parse(url);
String currentSchema = (String) jdbcUrl.getQueryProperties().getOrDefault("currentSchema","public");
return Optional.of(currentSchema);
}
@Override
public String getDatabaseType() {
return "PostgreSQL";
}
}
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] How to set the default schema for PostgreSQL [shardingsphere]
Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu commented on issue #32265:
URL: https://github.com/apache/shardingsphere/issues/32265#issuecomment-2250009245
This issue is duplicate with #17204, we will consider support PostgreSQL SEARCH PATH in future.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] How to set the default schema for PostgreSQL [shardingsphere]
Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu closed issue #32265: How to set the default schema for PostgreSQL
URL: https://github.com/apache/shardingsphere/issues/32265
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org