Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions crates/rupg-analyze/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,11 @@ impl Analyzer<'_> {
let (value, ty) = match &c.val {
Some(Node::Integer(v)) => (Value::Int4(*v), oid::INT4),
Some(Node::Float(text)) => match rupg_types::int8_in(text) {
// A literal that fits `int8` is an `int8`, and any other number is a `numeric`.
Ok(v) => (Value::Int8(v), oid::INT8),
// A literal that fits `int4`, such as `-2147483648`, is an `int4`. A literal that fits `int8` is an `int8`, and any other number is a `numeric`.
Ok(v) => match i32::try_from(v) {
Ok(v) => (Value::Int4(v), oid::INT4),
Err(_) => (Value::Int8(v), oid::INT8),
},
Err(_) => {
let v =
rupg_types::numeric_in(text, -1).map_err(|e| Error::from(e).at_opt(at))?;
Expand Down
2 changes: 1 addition & 1 deletion crates/rupg-func/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn numeric_to_int(call: &Call<'_>, args: &[Value]) -> Result<Value> {
}

/// `numeric_float8` and `numeric_float4`: the input function of the float type on the text of the number.
fn numeric_to_float(call: &Call<'_>, args: &[Value]) -> Result<Value> {
pub(crate) fn numeric_to_float(call: &Call<'_>, args: &[Value]) -> Result<Value> {
let Value::Numeric(n) = first(args)? else { return Err(bad_value()) };
let special = match n.sign() {
NumericSign::NaN => Some(f64::NAN),
Expand Down
Loading
Loading