2
如果我這樣做:返回值差異爲布爾
ActiveRecord::Base.connection.execute('select 1 as t').first
上的Postgres和MySQL我得到這個:
MySql: [1]
Postgres: {"t"=>"1"}
人能解釋這是什麼?
如果我這樣做:返回值差異爲布爾
ActiveRecord::Base.connection.execute('select 1 as t').first
上的Postgres和MySQL我得到這個:
MySql: [1]
Postgres: {"t"=>"1"}
人能解釋這是什麼?
無論錯誤在哪裏,這表明兩個數據庫之間有趣的差異(以及爲什麼交叉數據庫抽象很難)。
MySQL沒有真正的布爾類型。它僅使用tinyints作爲布爾值。
在MySQL:
SELECT true;
+------+
| TRUE |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
布爾表達式也評估爲整數:
select true is not false;
+-------------------+
| true is not false |
+-------------------+
| 1 |
+-------------------+
1 row in set (0.00 sec)
PostgreSQL的
PostgreSQL支持一個真正的布爾類型與任一 'T'或者返回一個'f'。
select true;
bool
------
t
(1 row)
select true is not false;
?column?
----------
t
(1 row)
注意你也可以投給整型布爾:
select 1::bool;
bool
------
t
(1 row)
select 2::bool;
bool
------
t
(1 row)
select 0::bool;
bool
------
f
(1 row)
顯然這些包的兩位作者曾如何解決布爾類型的問題,不同的想法。
推測是MySQL驅動程序中的一個錯誤。向開發者報告...... – 2011-06-14 12:35:24
我寧願說它是postgres驅動程序中的一個錯誤。 1是一個int,並以字符串的形式返回... – jriff 2011-06-15 07:53:07
然後,這兩個錯誤。在MySQL的情況下,整數應該返回它的名字... – 2011-06-15 10:02:45