Skip to content

Commit 38983f8

Browse files
committed
Improve doc comments around ast::Value::Interval
Intervals are confusing, this makes the interpretation of the individual fields more obvious.
1 parent b2b301e commit 38983f8

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/ast/value.rs

+30-2
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,45 @@ pub enum Value {
3535
/// `TIMESTAMP '...'` literals
3636
Timestamp(String),
3737
/// INTERVAL literals, roughly in the following format:
38-
/// `INTERVAL '<value>' <leading_field> [ (<leading_precision>) ]
39-
/// [ TO <last_field> [ (<fractional_seconds_precision>) ] ]`,
38+
///
39+
/// ```
40+
/// INTERVAL '<value>' <leading_field> [ (<leading_precision>) ]
41+
/// [ TO <last_field> [ (<fractional_seconds_precision>) ] ]
42+
/// ```
4043
/// e.g. `INTERVAL '123:45.67' MINUTE(3) TO SECOND(2)`.
4144
///
4245
/// The parser does not validate the `<value>`, nor does it ensure
4346
/// that the `<leading_field>` units >= the units in `<last_field>`,
4447
/// so the user will have to reject intervals like `HOUR TO YEAR`.
4548
Interval {
49+
/// The raw [value] that was present in `INTERVAL '[value]'`
4650
value: String,
51+
/// The unit of the first field in the interval. `INTERVAL 'T' MINUTE`
52+
/// means `T` is in minutes
4753
leading_field: DateTimeField,
54+
/// How many digits the leading field is allowed to occupy.
55+
///
56+
/// The interval `INTERVAL '1234' MINUTE(3)` is **illegal**, but `INTERVAL
57+
/// '123' MINUTE(3)` is fine.
58+
///
59+
/// This parser does not do any validation that fields fit.
4860
leading_precision: Option<u64>,
61+
/// How much precision to keep track of
62+
///
63+
/// If this is ommitted, then you are supposed to ignore all of the
64+
/// non-lead fields. If it is less precise than the final field, you
65+
/// are supposed to ignore the final field.
66+
///
67+
/// For the following specifications:
68+
///
69+
/// * `INTERVAL '1:1:1' HOURS TO SECONDS` the `last_field` gets
70+
/// `Some(DateTimeField::Second)` and interpreters should generate an
71+
/// interval equivalent to `3661` seconds.
72+
/// * In `INTERVAL '1:1:1' HOURS` the `last_field` gets `None` and
73+
/// interpreters should generate an interval equivalent to `3600`
74+
/// seconds.
75+
/// * In `INTERVAL '1:1:1' HOURS TO MINUTES` the interval should be
76+
/// equivalent to `3660` seconds.
4977
last_field: Option<DateTimeField>,
5078
/// The seconds precision can be specified in SQL source as
5179
/// `INTERVAL '__' SECOND(_, x)` (in which case the `leading_field`

0 commit comments

Comments
 (0)