sql - 如何处理postgresql的日期字段中的null
问题描述
我必须忽略null
日期列中的行。我该怎么做?
select s."SR Closed Date"::date,
s."Service Request Number",
a."Activity ID"
from sr_data_master s,
activity_master a
where s."Service Request Number" = a."Service Request Number"
and a."Service Request Number" is not null
and a."Service Tag" is not null
and a."Activity ID" is not null
and s."SR Closed Date"::date is not NULL
group by s."Service Request Number",
s."SR Closed Date"::date,
a."Activity ID";
我收到错误消息:
invalid input syntax for type date: "NULL"
解决方案
错误消息表明您的“日期”列(显然实际上不是日期列)包含字符串常量'NULL'
而不是实际值(因为将实际值null
转换为值没有问题)。null
date
您可以使用以下条件排除这些行:
and s."SR Closed Date" <> 'NULL'
但解决此问题的正确方法是将日期值存储在DATE
列中。那么您就不需要强制转换,也不能存储无效的日期值。
推荐阅读
- python - 创建聊天室 - 出现错误 [WinError 10038] 尝试对非套接字的操作进行操作
- android - Firebase auth 网络错误android sdk
- opencv - 我想将灰度与形状(无,224,224)转换为(224,224,3)
- python - 使用文件中的密钥对替换列表中的值
- python - python中matlab的release()的等效代码段/命令是什么?
- python - 如何在 Python 的弹出消息中显示按钮以及如何交互?
- python - 从 discord_webhookModule 中删除日志记录
- r - 使用下划线分隔的字符串中的每个单词添加行
- java - 春季批处理失败时如何继续处理处理器中的下一行?
- php - 确定 Laravel Fortify 中是否使用了恢复代码