我正在使用以下查询:
ALTER TABLE presales ALTER COLUMN code TYPE numeric(10,0);
Run Code Online (Sandbox Code Playgroud)
从更改列的数据类型character(20)来numeric(10,0),但我得到的错误:
列"代码"无法强制转换为数字类型
我从一个在Varchar中有原始feed的表中导入数据,我需要将varchar中的一列导入到一个字符串列中.我尝试使用<column_name>::integer以及to_number(<column_name>,'9999999')但是我收到错误,因为有一些空字段,我需要将它们检索为空或null到新表中.
如果有相同的功能,请告诉我.
当我执行
select max(column) from mytable;
Run Code Online (Sandbox Code Playgroud)
并且我的表没有行,它返回null.如何修改此select语句以使其返回零?
我有一些列类型int,但值为空.所以我想在插入数据库时将empty转换为null.我用代码:
function toDB($string) {
if ($string == '' || $string == "''") {
return 'null';
} else {
return "'$string'";
}
}
//age,month,year is type integer.
$name="Veo ve";
$age='10';
$month='';
$year='';
$query="Insert Into tr_view(name,age,month,year) values ({toDB($name)},{toDB($age)},{toDB($month)},{toDB($year)})
$db->setQuery($query);
$result= $db->query();
Run Code Online (Sandbox Code Playgroud)
但它显示错误:
pg_query(): Query failed: ERROR: syntax error at or near "{" LINE 153: {toDB(10)}, ^ in...
Run Code Online (Sandbox Code Playgroud)
为什么?