risingwave_common/types/
to_sql.rs1use std::error::Error;
16
17use bytes::BytesMut;
18use postgres_types::{IsNull, ToSql, Type, to_sql_checked};
19use risingwave_common::types::ScalarRefImpl;
20
21use crate::types::ScalarImpl;
22
23impl ToSql for ScalarImpl {
24 to_sql_checked!();
25
26 fn to_sql(&self, ty: &Type, out: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>>
27 where
28 Self: Sized,
29 {
30 match self {
31 ScalarImpl::Int16(v) => v.to_sql(ty, out),
32 ScalarImpl::Int32(v) => v.to_sql(ty, out),
33 ScalarImpl::Int64(v) => v.to_sql(ty, out),
34 ScalarImpl::Serial(v) => v.to_sql(ty, out),
35 ScalarImpl::Float32(v) => v.to_sql(ty, out),
36 ScalarImpl::Float64(v) => v.to_sql(ty, out),
37 ScalarImpl::Utf8(v) => v.to_sql(ty, out),
38 ScalarImpl::Bool(v) => v.to_sql(ty, out),
39 ScalarImpl::Decimal(v) => v.to_sql(ty, out),
40 ScalarImpl::Interval(v) => v.to_sql(ty, out),
41 ScalarImpl::Date(v) => v.to_sql(ty, out),
42 ScalarImpl::Timestamp(v) => v.to_sql(ty, out),
43 ScalarImpl::Timestamptz(v) => v.to_sql(ty, out),
44 ScalarImpl::Time(v) => v.to_sql(ty, out),
45 ScalarImpl::Bytea(v) => (&**v).to_sql(ty, out),
46 ScalarImpl::Jsonb(v) => v.to_sql(ty, out),
47 ScalarImpl::Vector(_)
48 | ScalarImpl::Int256(_)
49 | ScalarImpl::Struct(_)
50 | ScalarImpl::List(_) => {
51 bail_not_implemented!("the postgres encoding for {ty} is unsupported")
52 }
53 ScalarImpl::Map(_) => todo!(),
54 }
55 }
56
57 fn accepts(_ty: &Type) -> bool
59 where
60 Self: Sized,
61 {
62 true
63 }
64}
65
66impl ToSql for ScalarRefImpl<'_> {
67 to_sql_checked!();
68
69 fn to_sql(&self, ty: &Type, out: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>>
70 where
71 Self: Sized,
72 {
73 match self {
74 ScalarRefImpl::Int16(v) => v.to_sql(ty, out),
75 ScalarRefImpl::Int32(v) => v.to_sql(ty, out),
76 ScalarRefImpl::Int64(v) => v.to_sql(ty, out),
77 ScalarRefImpl::Serial(v) => v.to_sql(ty, out),
78 ScalarRefImpl::Float32(v) => v.to_sql(ty, out),
79 ScalarRefImpl::Float64(v) => v.to_sql(ty, out),
80 ScalarRefImpl::Utf8(v) => v.to_sql(ty, out),
81 ScalarRefImpl::Bool(v) => v.to_sql(ty, out),
82 ScalarRefImpl::Decimal(v) => v.to_sql(ty, out),
83 ScalarRefImpl::Interval(v) => v.to_sql(ty, out),
84 ScalarRefImpl::Date(v) => v.to_sql(ty, out),
85 ScalarRefImpl::Timestamp(v) => v.to_sql(ty, out),
86 ScalarRefImpl::Timestamptz(v) => v.to_sql(ty, out),
87 ScalarRefImpl::Time(v) => v.to_sql(ty, out),
88 ScalarRefImpl::Bytea(v) => (&**v).to_sql(ty, out),
89 ScalarRefImpl::Jsonb(v) => v.to_sql(ty, out),
90 ScalarRefImpl::Vector(_)
91 | ScalarRefImpl::Int256(_)
92 | ScalarRefImpl::Struct(_)
93 | ScalarRefImpl::List(_) => {
94 bail_not_implemented!("the postgres encoding for {ty} is unsupported")
95 }
96 ScalarRefImpl::Map(_) => todo!(),
97 }
98 }
99
100 fn accepts(_ty: &Type) -> bool
102 where
103 Self: Sized,
104 {
105 true
106 }
107}