programing

postgres where 절 비교 타임스탬프

linuxpc 2023. 5. 11. 21:10
반응형

postgres where 절 비교 타임스탬프

열이 데이터 유형인 테이블이 있습니다.timestamp

일에 해당하는 모든 행을 선택하고자 하는 하루 동안 여러 레코드가 포함되어 있습니다.

제가 그걸 어떻게 합니까?

당신이 정말로 의미한다고 가정하면timestamp없기 때문에datetime포스트그레스에서

타임스탬프 열을 날짜로 캐스팅하여 시간 부분을 제거합니다.

select *
from the_table
where the_timestamp_column::date = date '2015-07-15';

이렇게 하면 7월 15일부터 모든 행이 반환됩니다.

위의 내용은 다음에 인덱스를 사용하지 않습니다.the_timestamp_column성능이 중요한 경우 해당 식에 인덱스를 생성하거나 범위 조건을 사용해야 합니다.

select *
from the_table
where the_timestamp_column >= timestamp '2015-07-15 00:00:00'
  and the_timestamp_column < timestamp '2015-07-16 00:00:00';

언급URL : https://stackoverflow.com/questions/31433747/postgres-where-clause-compare-timestamp

반응형