Skip to content

Commit 8cd340d

Browse files
authored
Merge pull request diesel-rs#926 from Eijebong/warn_on_varchar_array
Emit a message on stderr when infering a varchar[]
2 parents 73a6da5 + c76f5d1 commit 8cd340d

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

  • diesel_infer_schema/src

diesel_infer_schema/src/pg.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::error::Error;
2+
use std::io::{stderr, Write};
23

34
use data_structures::*;
45

@@ -10,6 +11,14 @@ pub fn determine_column_type(attr: &ColumnInformation) -> Result<ColumnType, Box
1011
&attr.type_name
1112
};
1213

14+
let tpe_is_varchar = tpe.to_lowercase() == "varchar";
15+
16+
// Postgres doesn't coerce varchar[] to text[] so print out a message to inform
17+
// the user.
18+
if tpe_is_varchar && is_array {
19+
writeln!(&mut stderr(), "The column `{}` is of type `varchar[]`. This will cause problems when using Diesel. You should consider changing the column type to `text[]`.", attr.column_name)?;
20+
}
21+
1322
Ok(ColumnType {
1423
path: vec!["diesel".into(), "types".into(), capitalize(tpe)],
1524
is_array: is_array,

0 commit comments

Comments
 (0)