Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database PostgreSql+将布尔类型转换为字符类型_Database_Postgresql_Sql - Fatal编程技术网

Database PostgreSql+将布尔类型转换为字符类型

Database PostgreSql+将布尔类型转换为字符类型,database,postgresql,sql,Database,Postgresql,Sql,在这里,我无法在PostgreSQL查询中将布尔值转换为字符 SELECT *FROM ltl_class_nmfc_aliases WHERE ltl_class_nmfc_aliases.id NOT IN(SELECT ltl_class_nmfc_aliases_id FROM commodities_shippeds WHERE commodities_shipped_obj_type LIKE 'ClientOffice') OR ltl_class_id IS NULL

在这里,我无法在PostgreSQL查询中将布尔值转换为字符

SELECT *FROM ltl_class_nmfc_aliases 
WHERE ltl_class_nmfc_aliases.id 
NOT IN(SELECT ltl_class_nmfc_aliases_id FROM commodities_shippeds 
WHERE commodities_shipped_obj_type LIKE 'ClientOffice') 
OR ltl_class_id IS NULL 
AND lower(commodity_description_alias) LIKE E'%%' 
AND lower(ltl_value) LIKE E'%92.5%' 
AND hazardous :: integer LIKE E  '%%' 
AND cast(schedule_b as character varying(255)) LIKE E'%%' 
AND cast(harmonized_tariff as character varying(255)) LIKE E'%%' 
ORDER BY commodity_description_alias,ltl_value LIMIT 25;
在这里,我无法在和hazardous::integer上进行类型转换,如E“%” 建议我如何进行类型转换?

使用case语句如何

(case when hazardous then 'Bad juju' else 'Ok.' end) as safety
您还可以使用cast语句:

postgres=# select cast(1 as boolean);
 bool
------
 t

postgres=# select cast(0 as boolean);
 bool
------
 f

postgres=# select cast('false' as boolean);
 bool
------
 f

postgres=# select cast('False' as boolean);
 bool
------
 f

postgres=# select cast('T' as boolean);
 bool
------
 t

postgres=# select cast('F' as boolean);
 bool
------
 f

postgres=# select cast('Y' as boolean);
 bool
------
 t

postgres=# select cast('N' as boolean);
 bool
------
 f
因此可能是:

 select ... where ... and hazardous = cast(:your_variable as bool)
您还可以强制转换为varchar:

select cast(hazardous to varchar)...
一些数据库驱动程序实现(如Borland的BDE)无法满足这一要求,因为它们希望varchar字段具有显式的列宽


如果您只是筛选hazardous=true,请使用just AND hazardous。

我正在尝试这个案例,但我没有获得任何成功。我现在要试试你的代码。选择*从ltl\U类\U nmfc\U别名左外部加入ltl\U类\U nmfc上的ltl\U nmfc。id=ltl\U类\U nmfc\U别名。ltl\U类\U nmfc\id左外部加入ltl\U类上的ltl\U类。id=ltl\U类\U nmfcs.ltl\U类\U id其中ltl\U类\U nmfc\U别名。id不选择ltl\U类\U别名“ClientOffice”或ltl_class_id等商品类型为空,而lowercommodity_描述_别名为E“%”,LowerTLU值为E“%92.5%”,case when hazardous则为“True”或“False”end,castschedule_b则为字符变量255,如E“%”;错误:AND的参数必须是布尔类型,而不是where子句中的TEXT类型use和case when HAZURE然后是'True'否则'False'end='True'如果您没有将hazadous与某物进行比较,只是筛选value=True,则正确的测试是公正和危险的