間隔リテラル - Amazon Redshift

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

間隔リテラル

Following are rules for working with interval literals supported by Amazon Redshift.

12 hours または 6 weeks など、特定の期間を識別するには、間隔リテラルを使用します。これらの間隔リテラルは、日時式を必要とする条件および計算の中で使用できます。

注記

You can't use the INTERVAL data type for columns in Amazon Redshift tables.

An interval is expressed as a combination of the INTERVAL keyword with a numeric quantity and a supported date part, for example INTERVAL '7 days' or INTERVAL '59 minutes'. You can connect several quantities and units to form a more precise interval, for example: INTERVAL '7 days, 3 hours, 59 minutes'. Abbreviations and plurals of each unit are also supported; for example: 5 s, 5 second, and 5 seconds are equivalent intervals.

If you don't specify a date part, the interval value represents seconds. 数量値は小数として指定できます (例えば、0.5 days)。

Examples

次の例に、さまざまな間隔値を使用した一連の計算を示します。

The following adds 1 second to the specified date.

select caldate + interval '1 second' as dateplus from date where caldate='12-31-2008'; dateplus --------------------- 2008-12-31 00:00:01 (1 row)

The following adds 1 minute to the specified date.

select caldate + interval '1 minute' as dateplus from date where caldate='12-31-2008'; dateplus --------------------- 2008-12-31 00:01:00 (1 row)

The following adds 3 hours and 35 minutes to the specified date.

select caldate + interval '3 hours, 35 minutes' as dateplus from date where caldate='12-31-2008'; dateplus --------------------- 2008-12-31 03:35:00 (1 row)

The following adds 52 weeks to the specified date.

select caldate + interval '52 weeks' as dateplus from date where caldate='12-31-2008'; dateplus --------------------- 2009-12-30 00:00:00 (1 row)

The following adds 1 week, 1 hour, 1 minute, and 1 second to the specified date.

select caldate + interval '1w, 1h, 1m, 1s' as dateplus from date where caldate='12-31-2008'; dateplus --------------------- 2009-01-07 01:01:01 (1 row)

The following adds 12 hours (half a day) to the specified date.

select caldate + interval '0.5 days' as dateplus from date where caldate='12-31-2008'; dateplus --------------------- 2008-12-31 12:00:00 (1 row)