use spg_engine::{Engine, QueryResult};
fn text(e: &mut Engine, sql: &str) -> String {
match e.execute(sql).unwrap() {
QueryResult::Rows { rows, .. } => match &rows[0].values[0] {
spg_storage::Value::Text(s) => s.to_string(),
v => format!("{v:?}"),
},
_ => panic!("rows"),
}
}
#[test]
fn trunc_numeric_stays_numeric() {
let mut e = Engine::new();
assert_eq!(text(&mut e, "SELECT trunc(3.14159, 2)::text"), "3.14");
assert_eq!(
text(&mut e, "SELECT trunc(1234567.891234567891, 8)::text"),
"1234567.89123456"
);
assert_eq!(text(&mut e, "SELECT trunc(-3.14159, 2)::text"), "-3.14");
assert_eq!(text(&mut e, "SELECT trunc(12345.0, -2)::text"), "12300");
assert_eq!(text(&mut e, "SELECT trunc(3.1, 4)::text"), "3.1000");
}