两个Postgres实例的结果不同

huangapple go评论86阅读模式
英文:

Different results with 2 Postgres instances

问题

我在本地使用Postgres App运行一个Postgres 9.2.2服务器,ssmode=disable。所有的表都按照预期创建,并且SELECT查询也正常工作。

当我在Heroku上创建一个Postgres实例时(根据psql,服务器版本为9.1.6,ssmode=require),除了查询不返回结果外,其他都正常工作。

具体的查询是

<!-- language: sql -->

SELECT * FROM &quot;captcha&quot; WHERE &quot;cid&quot; = $1 LIMIT $2

cid/$1的类型是character varying(20)

当通过psql连接到远程实例并手动执行查询时,行按预期返回。我只是不明白可能导致这种不同行为的原因。

主要嫌疑人应该是我使用的驱动程序bmizerany/pq,但还可能有其他导致这种行为的错误来源吗?

更新:

我尝试了一个简单的查询,结果相同:结果集中没有行

SELECT * FROM &quot;captcha&quot; WHERE &quot;cid&quot; = &#39;JQRPm6qRpYukXCiPUpHZ&#39; LIMIT 1

更新2:

这与bytea字段有关,以下代码片段说明了在这两个PG版本上执行时的问题https://gist.github.com/eaigner/5004468

英文:

I run a Postgres 9.2.2 server locally using the Postgres App with ssmode=disable. All the tables are created like they should be and SELECT queries work as expected.

When I create a Postgres instance on Heroku (the server is 9.1.6 according to psql, ssmode=require), everything works fine, except that a query returns no results, where the local postgres instance does.

The specific query is

<!-- language: sql -->

SELECT * FROM &quot;captcha&quot; WHERE &quot;cid&quot; = $1 LIMIT $2

and cid/$1 is of type character varying(20).

When connecting to the remote instance via psql and executing the query manually, the rows were returned as expected. I just don't understand what could possibly cause that different behavior.

The primary suspect would be the driver that I use bmizerany/pq, but could there be other error sources for this behavior?

UPDATE:

I tried it with a plain query, same result: No rows in result set

SELECT * FROM &quot;captcha&quot; WHERE &quot;cid&quot; = &#39;JQRPm6qRpYukXCiPUpHZ&#39; LIMIT 1

UPDATE 2:

It has something todo with the bytea field, the following snippet illustrates the problem when executing on those 2 PG versions https://gist.github.com/eaigner/5004468

答案1

得分: 2

问题是,Heroku使用了非默认的bytea_output。因此,解决这个问题的方法是在运行查询之前设置bytea_outputhex

英文:

The problem is, that Heroku uses a non-default bytea_output. So a workaround to deal with this was

SET bytea_output = &#39;hex&#39;;

before running the query

答案2

得分: 1

请尝试使用PREPARE/EXECUTEpq使用的是“扩展”查询协议,它使用绑定而不是“简单”协议,后者只是文本,因此这样会更好地模拟交互。

请提交一个错误报告。

英文:

Try using PREPARE/EXECUTE. pq uses the 'extended' query protocol which uses bind rather than the 'simple' protocol that is just text, so that'll model the interaction better.

Please file a bug.

huangapple
  • 本文由 发表于 2013年2月21日 08:49:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/14992757.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定