Skip to content

Commit 61805ce

Browse files
committed
Support TIMESTAMP[]
1 parent e34c835 commit 61805ce

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ types. The driver currently supports the following conversions:
286286
<td>types::array::ArrayBase&lt;Option&lt;i64&gt;&gt;</td>
287287
<td>INT8[], INT8[][], ...</td>
288288
</tr>
289+
<tr>
290+
<td>types::array::ArrayBase&lt;Option&lt;Timespec&gt;&gt;</td>
291+
<td>TIMESTAMP[], TIMESTAMP[][], ...</td>
292+
</tr>
289293
<tr>
290294
<td>types::array::ArrayBase&lt;Option&lt;f32&gt;&gt;</td>
291295
<td>FLOAT4[], FLOAT4[][], ...</td>

test.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,17 @@ fn test_int8array_params() {
480480
test_array_params!("INT8", 0i64, "0", 1i64, "1", 2i64, "2");
481481
}
482482
483+
#[test]
484+
fn test_timestamparray_params() {
485+
fn make_check<'a>(time: &'a str) -> (Timespec, &'a str) {
486+
(time::strptime(time, "%Y-%m-%d %H:%M:%S.%f").unwrap().to_timespec(), time)
487+
}
488+
let (v1, s1) = make_check("1970-01-01 00:00:00.01");
489+
let (v2, s2) = make_check("1965-09-25 11:19:33.100314");
490+
let (v3, s3) = make_check("2010-02-09 23:11:45.1202");
491+
test_array_params!("TIMESTAMP", v1, s1, v2, s2, v3, s3);
492+
}
493+
483494
#[test]
484495
fn test_float4array_params() {
485496
test_array_params!("FLOAT4", 0f32, "0", 1.5f32, "1.5", 0.009f32, ".009");

types/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static FLAOT8ARRAYOID: Oid = 1022;
4747
static BPCHAROID: Oid = 1042;
4848
static VARCHAROID: Oid = 1043;
4949
static TIMESTAMPOID: Oid = 1114;
50+
static TIMESTAMPARRAYOID: Oid = 1115;
5051
static TIMESTAMPZOID: Oid = 1184;
5152
static UUIDOID: Oid = 2950;
5253
static INT4RANGEOID: Oid = 3904;
@@ -169,6 +170,8 @@ make_postgres_type!(
169170
FLAOT8ARRAYOID => PgFloat8Array member PgFloat8,
170171
#[doc="TIMESTAMP"]
171172
TIMESTAMPOID => PgTimestamp,
173+
#[doc="TIMESTAMP[]"]
174+
TIMESTAMPARRAYOID => PgTimestampArray member PgTimestamp,
172175
#[doc="TIMESTAMP WITH TIME ZONE"]
173176
TIMESTAMPZOID => PgTimestampZ,
174177
#[doc="CHAR(n)/CHARACTER(n)"]
@@ -403,6 +406,7 @@ from_array_impl!(PgInt2Array, i16)
403406
from_array_impl!(PgInt4Array, i32)
404407
from_array_impl!(PgTextArray | PgCharNArray | PgVarcharArray, ~str)
405408
from_array_impl!(PgInt8Array, i64)
409+
from_array_impl!(PgTimestampArray, Timespec)
406410
from_array_impl!(PgFloat4Array, f32)
407411
from_array_impl!(PgFloat8Array, f64)
408412

@@ -700,6 +704,7 @@ to_array_impl!(PgInt2Array, i16)
700704
to_array_impl!(PgInt4Array, i32)
701705
to_array_impl!(PgTextArray | PgCharNArray | PgVarcharArray, ~str)
702706
to_array_impl!(PgInt8Array, i64)
707+
to_array_impl!(PgTimestampArray, Timespec)
703708
to_array_impl!(PgFloat4Array, f32)
704709
to_array_impl!(PgFloat8Array, f64)
705710

0 commit comments

Comments
 (0)