简体   繁体   English

具有不合格表名的存储过程不适用于 Babelfish

[英]Stored procedures with unqualified table names not working with Babelfish

I have created a Babelfish-enabled Postgres database in RDS.我在 RDS 中创建了一个支持 Babelfish 的 Postgres 数据库。 I connected with SSMS and created a Database named 'demo'.我连接了 SSMS 并创建了一个名为“demo”的数据库。 Within 'demo' I created a Schema named 'biz'.在“演示”中,我创建了一个名为“biz”的架构。 I created my tables and stored procedures in the 'biz' schema.我在“商业”模式中创建了我的表和存储过程。 The stored procedures used unqualified table names.存储过程使用了不合格的表名。 Finally, I wrote a.Net program to do some testing.最后,我写了一个.Net程序来做一些测试。 I use the System.Data.SqlClient Connection and Command classes and I can connect to the database.我使用 System.Data.SqlClient Connection 和 Command 类,我可以连接到数据库。 When I execute a stored procedure I get the 'relation "X" does not exist.'当我执行存储过程时,我得到“关系“X”不存在”。 error.错误。 If I alter my stored procedure and qualify the table names with the 'biz' schema the error goes away.如果我更改存储过程并使用“biz”模式限定表名,错误就会消失。

How do I avoid having to qualify the table names with the schema?如何避免必须使用模式限定表名?

For example: After creating a Babelfish enabled Postgres cluster I executed these statements in SSMS:例如:在创建了一个启用了 Babelfish 的 Postgres 集群后,我在 SSMS 中执行了这些语句:

create database demo
use demo
create schema biz
create table [biz].[cities](
    [city] varchar(128),
    [state] varchar(128)
    )

create procedure [biz].[p_getcities] as
begin
    select * from cities
end

insert into [biz].[cities](city, state) values ('Portland', 'OR')
insert into [biz].[cities](city, state) values ('Richmond', 'VA')

exec [biz].p_getcities

And I get this error message after running p_getcities:运行 p_getcities 后我收到此错误消息:

Msg 33557097, Level 16, State 1, Line 21 relation "cities" does not exist Msg 33557097, Level 16, State 1, Line 21 relation "cities" does not exist

When I switch to pgAdmin and try to run the stored procedure like this:当我切换到 pgAdmin 并尝试像这样运行存储过程时:

CALL biz.p_getcities()

I get a similar error:我得到一个类似的错误:

ERROR: relation "cities" does not exist LINE 1: select * from cities ^ QUERY: select * from cities CONTEXT: PL/tsql function biz.p_getcities() line 2 at SQL statement SQL state: 42P01错误:关系“城市”不存在第1行1:select *来自城市 ^查询:select *来自城市上下文:PL/TSQL function BIZ.P_GETCITITS(P_GETCIES(P_GETCIES)()第2行,第2号

However, when I set the search_path like this:但是,当我这样设置 search_path 时:

set search_path to biz

And the execute the stored procedure I get the expected results:并执行存储过程我得到了预期的结果:

Portland OR Richmond VA波特兰或里士满 VA

Is there an equivalent to search_path in Babelfish? Babelfish 中是否有等同于 search_path 的东西?

This explanation has been provided by Rob Verschoor of rcv-aws此解释由 rcv-aws 的Rob Verschoor提供

What is happening here is that the name resolution inside the procedure biz.p_getcities does not correctly resolve the table name.这里发生的是过程 biz.p_getcities 中的名称解析没有正确解析表名。 It resolves it to 'dbo' schema while it should resolve it to 'biz' schema.它将它解析为“dbo”模式,而它应该将它解析为“biz”模式。 As you noted, this is related to the search_path setting, and this is not set correctly in this case.如您所述,这与 search_path 设置有关,在这种情况下设置不正确。 This is a known bug and we hope to fix it soon.这是一个已知的错误,我们希望尽快修复它。

Until then, the workaround is to qualify the table name with the schema name, ie select * from biz.cities在此之前,解决方法是使用架构名称限定表名,即来自 biz.cities 的 select *

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM