类型为timestamp的输入语法无效

时间:2018-05-30 07:02:04

标签: database postgresql azure azure-postgresql

运行以下代码时,我收到一条错误,指出来自admission_datetime的类型timestamp的输入语法无效。

    UPDATE ccsm.stg_demographics_baseline
    SET xx_los_days =
    (CASE WHEN admission_datetime IS NULL OR 
    date_trunc('day',admission_datetime) = ''
    THEN NULL
    WHEN discharge_datetime IS NULL OR 
    date_trunc('day',discharge_datetime) = ''
    THEN date_diff('day', admission_datetime, CURRENT_DATE)
    ELSE
    date_diff('day', admission_datetime, discharge_datetime)
    END);
enter code here

1 个答案:

答案 0 :(得分:0)

请参阅date_trunc documentation

  

返回值的类型为timestamp或interval,其中所有字段的重要性均低于所选字段的设置为零(或一个,日期和月份)。

所以你无法将它与空字符串进行比较:

date_trunc('day', admission_datetime) = ''

invalid input syntax for type timestamp错误消息涉及空字符串(''),而不是admission_datetime列。

此外,PostgreSQL中没有date_diff函数。只需从另一个timestamp中减去一个interval,您将获得SELECT timestamp '2001-09-29 03:00' - timestamp '2001-09-27 12:00' 结果:

interval '1 day 15:00:00'

你会得到

SELECT DATE_PART('day', timestamp '2001-09-29 03:00' - timestamp '2001-09-27 12:00')

如果您需要的差异,请尝试以下操作:

1

结果为DATEDIFF

请参阅here以了解PostgreSQL中public class Controller implements Initializable { //defines the incremental change in color private static final int COLOR_INCREMENT = 30; //initial rgb values (green) private int red = 0, green = 255, blue = 0; @FXML private Button button2; @FXML private DatePicker datePicker; @FXML private Label lbColor; @Override public void initialize(URL location, ResourceBundle resources) { button2.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { lbColor.setStyle("-fx-background-color:"+ getColorString()+";"); } }); //Cell factory omitted. Not needed to demonstrate the question nor the answer } //increment color by COLOR_INCREMENT to step from green to yellow to red //and return string representation of it //green is rgb is (0, 255, 0) //yellow rgb is (255, 255, 0) //red in rgb is (255, 0, 0) private String getColorString() { if((green == 255) && (red < 255)) { red = (red + COLOR_INCREMENT) > 255 ? 255 : (red + COLOR_INCREMENT) ; }else if( (red == 255) && (green > 0)){ green = (green - COLOR_INCREMENT) < 0 ? 0 : (green - COLOR_INCREMENT) ; } StringBuilder sb = new StringBuilder("rgb("); sb.append(red).append(",") .append(green).append(",") .append(blue).append(")"); return sb.toString(); } } 类似表达式的示例。