设置 Vertica 数据库的默认架构

发布于 2024-11-09 17:50:58 字数 453 浏览 8 评论 0原文

我正在使用 Play 构建一个 Web 应用程序!以 Vertica 数据库作为后端。 Vertica 的 JDBC 连接字符串包含服务器和数据库名称,但我的表位于特定架构下(例如“dev_myschema”)。因此,我应该将我的表称为“dev_myschema.mytable”。生产模式中也有所有这些表的精确副本(例如“prod_myschema”)以及真实数据。

我想在配置文件中设置这个模式名称,以便可以轻松地在这两个模式之间切换。现在,我在帮助程序类中有一个 getConnection 方法,它执行 DB.getConnection() 并将配置的架构设置为该连接对象的默认架构。但是,这在其他模型类中并没有帮助,在其他模型类中连同其实体注释(@Entity @Table(name = dev_myschema.mytable))一起提到

有没有一种方法可以在配置文件中指定模式名称并是否通过连接方法以及模型注释读取了它?

谢谢。

I am building a web application using Play! with Vertica database as back-end. The JDBC connection string for Vertica contains the server and database name, but my tables are under a specific schema (say "dev_myschema"). Thus, I should refer to my table as "dev_myschema.mytable". There is an exact copy of all these tables in a production schema as well (say "prod_myschema") with real data.

I would like to set this schema name in the configuration file so that it is easy to switch between these two schema. For now, I have a getConnection method in a helper class, that does DB.getConnection() and sets the configured schema as the default schema for that connection object. However, the same does not help in other model classes where it is mentioned along with its Entity annotation (@Entity @Table(name=dev_myschema.mytable))

Is there a way by which I can specify the schema name in the configuration file and have it read by the connection method as well as the model annotations?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

东北女汉子 2024-11-16 17:50:58

尤金几乎正确,但缺少一个下划线。设置默认架构的正确 Vertica SQL 语法是:

set search_path to dev_myschema

正如 Eugene 建议的,如果您使用低级 JDBC,一旦创建 Connection 对象,您就可以执行以下操作:

conn.createStatement().executeUpdate("set search_path to " + schemaName);

Eugene got it almost correct, but was missing an underscore. The correct Vertica SQL syntax to set the default schema is:

set search_path to dev_myschema

As Eugene suggested, if you are using low-level JDBC, as soon as you create your Connection object you can do:

conn.createStatement().executeUpdate("set search_path to " + schemaName);
狠疯拽 2024-11-16 17:50:58

据我所知(我刚刚浏览了 4.1.7 文档),目前还没有办法将模式设置为默认模式。

As far as I'm aware (and I just scanned the 4.1.7 documentation), there is no way as of yet to set a schema as the default.

饮湿 2024-11-16 17:50:58

根据 sql 指南,默认模式是在搜索树中找到的第一个模式。也许你可以利用它并确保首先找到你的副本。

according to the sql guide the default schema is the first one found in your search tree. maybe you could exploit that and make sure your copy is found first.

回眸一遍 2024-11-16 17:50:58

如果我使用我的开发模式,我处理这个问题的方法是执行“设置搜索路径”命令。因此,一旦创建了 Vertica 连接对象,请执行以下命令:

    "set search path to dev_myschema"

在我的应用程序代码中,我只是让我的 Vertica 对象检查环境/配置变量,如果存在“dev schema”设置,则会执行该语句建立连接后。我的生产配置没有该设置,因此在这种情况下它将仅使用默认架构,而不会产生每次执行该语句的额外开销。

They way I handle this issue is by executing a "set search path" command if I am using my development schema. So, as soon as your Vertica connection object is created, execute the following command:

    "set search path to dev_myschema"

In my application code, I just have my Vertica object check an environment/config variable, and if the "dev schema" setting is present, it executes that statement upon establishing the connection. My production config doesn't have that setting, so it will just use the default schema in that case and not incur the additional overhead of executing that statement every time.

幻想少年梦 2024-11-16 17:50:58

在 7.0 中,管理员可以通过发出以下命令在用户级别进行设置:

alter user user_name search_path schema1,schema2;

In 7.0, admin can set it at user level by issuing below command:

alter user user_name search_path schema1,schema2;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文