我在使用 postgres 时遇到问题,它与 mysql 非常不同(类型数据 string_numeric 和 numeric)。
我有一个对 varchar
类型的类型列的查询。
简单的例子
表A
id(int) | kode(string) | name(string)
--------+--------------+-------------
1 | 2 | yuan
在mysql中我们可以通过以下方式获取数据
select *
from A
where kode = 2;
但在 Postgres 中,这是错误的 SQL,因为数据列 kode
的类型是字符串,因此必须添加 ' 来构建查询,例如
select *
from A
where kode = '2';
如何设置Postgres像mysql一样使用SQL(关闭严格模式)?
最佳答案
您可以将条件中的列
转换为INT
。
select * from A where kode::Int = 2;
我相信 postgresql
没有严格模式
选项。
按照 Akina 的建议。
select * from A where kode= 2::varchar(30);
关于mysql - 如何在 PostgreSQL 中关闭严格模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59747721/