diff --git a/e2e_test/batch/catalog/pg_cast.slt.part b/e2e_test/batch/catalog/pg_cast.slt.part index b8ab68a5ed5cd..b1558d1e144c4 100644 --- a/e2e_test/batch/catalog/pg_cast.slt.part +++ b/e2e_test/batch/catalog/pg_cast.slt.part @@ -82,8 +82,9 @@ SELECT * FROM pg_catalog.pg_cast; 78 3802 701 e 79 3802 1700 e 80 3802 1043 a -81 1301 701 e -82 1301 1043 a +81 20 20 e +82 1301 701 e +83 1301 1043 a query TT rowsort SELECT s.typname, t.typname diff --git a/src/common/src/types/serial.rs b/src/common/src/types/serial.rs index 9bfbf5e4fcac7..5c84c95fa0f7a 100644 --- a/src/common/src/types/serial.rs +++ b/src/common/src/types/serial.rs @@ -26,6 +26,12 @@ use crate::util::row_id::RowId; #[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Default, Hash)] pub struct Serial(i64); +impl From for i64 { + fn from(value: Serial) -> i64 { + value.0 + } +} + impl From for Serial { fn from(value: i64) -> Self { Self(value) diff --git a/src/expr/impl/src/scalar/cast.rs b/src/expr/impl/src/scalar/cast.rs index dc81e3ab77bac..bf8afc7712f93 100644 --- a/src/expr/impl/src/scalar/cast.rs +++ b/src/expr/impl/src/scalar/cast.rs @@ -87,6 +87,7 @@ pub fn jsonb_to_number>(v: JsonbRef<'_>) -> Result { #[function("cast(int4) -> int2")] #[function("cast(int8) -> int2")] #[function("cast(int8) -> int4")] +#[function("cast(serial) -> int8")] #[function("cast(float4) -> int2")] #[function("cast(float8) -> int2")] #[function("cast(float4) -> int4")] diff --git a/src/frontend/src/expr/type_inference/cast.rs b/src/frontend/src/expr/type_inference/cast.rs index aa7e1c8ee9192..1f1a96e92b826 100644 --- a/src/frontend/src/expr/type_inference/cast.rs +++ b/src/frontend/src/expr/type_inference/cast.rs @@ -216,22 +216,23 @@ pub static CAST_MAP: LazyLock = LazyLock::new(|| { use DataTypeName::*; const CAST_TABLE: &[(&str, DataTypeName)] = &[ // 123456789ABCDEF - (". e a", Boolean), // 0 - (" .iiiiii a", Int16), // 1 - ("ea.iiiii a", Int32), // 2 - (" aa.iiii a", Int64), // 3 - (" aaa.ii a", Decimal), // 4 - (" aaaa.i a", Float32), // 5 - (" aaaaa. a", Float64), // 6 - (" e. a", Int256), // 7 - (" .ii a", Date), // 8 - (" a.ia a", Timestamp), // 9 - (" aa.a a", Timestamptz), // A - (" .i a", Time), // B - (" a. a", Interval), // C - ("eeeeeee . a", Jsonb), // D - (" .a", Bytea), // E - ("eeeeeeeeeeeeeee.", Varchar), // F + (". e a ", Boolean), // 0 + (" .iiiiii a ", Int16), // 1 + ("ea.iiiii a ", Int32), // 2 + (" aa.iiii a ", Int64), // 3 + (" aaa.ii a ", Decimal), // 4 + (" aaaa.i a ", Float32), // 5 + (" aaaaa. a ", Float64), // 6 + (" e. a ", Int256), // 7 + (" .ii a ", Date), // 8 + (" a.ia a ", Timestamp), // 9 + (" aa.a a ", Timestamptz), // A + (" .i a ", Time), // B + (" a. a ", Interval), // C + ("eeeeeee . a ", Jsonb), // D + (" .a ", Bytea), // E + ("eeeeeeeeeeeeeee. ", Varchar), // F + (" e .", Serial), ]; let mut map = BTreeMap::new(); for (row, source) in CAST_TABLE {