mysql - 如何在 PostgreSQL 中关闭严格模式

标签 mysql postgresql

我在使用 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/

相关文章:

mysql - 在 JSF 中使用国际化时出现的问题

postgresql - PostgreSQL 有哈希函数吗?

sql - 查询分隔,然后在postgresql中统计逗号分隔值的字段

postgresql - Serverless-framework postgresql 版本升级问题

arrays - 如何使用 PostgreSQL 更新 JSON 数组

mysql - 在 Mysql 中添加带有 select 语句的 "total sum"行

mysql - 转换Mysql中的查询

php - 使用 php mysql 将 auto_increment 主值设置为其他字段

php - 如何为新用户生成安全密码?

sql - 为什么 Postgres EXPLAIN ANALYZE execution_time 与我运行实际查询时不同?