(
scx: &StatementContext,
CopyStatement {
relation,
direction,
target,
options,
}: CopyStatement<Aug>,
)
| 2110 | ); |
| 2111 | |
| 2112 | pub fn plan_copy( |
| 2113 | scx: &StatementContext, |
| 2114 | CopyStatement { |
| 2115 | relation, |
| 2116 | direction, |
| 2117 | target, |
| 2118 | options, |
| 2119 | }: CopyStatement<Aug>, |
| 2120 | ) -> Result<Plan, PlanError> { |
| 2121 | let options = CopyOptionExtracted::try_from(options)?; |
| 2122 | // Parse any user-provided FORMAT option. If not provided, will default to |
| 2123 | // Text for COPY TO STDOUT and COPY FROM STDIN, but will error for COPY TO <expr>. |
| 2124 | let format = options |
| 2125 | .format |
| 2126 | .as_ref() |
| 2127 | .map(|format| match format.to_lowercase().as_str() { |
| 2128 | "text" => Ok(CopyFormat::Text), |
| 2129 | "csv" => Ok(CopyFormat::Csv), |
| 2130 | "binary" => Ok(CopyFormat::Binary), |
| 2131 | "parquet" => Ok(CopyFormat::Parquet), |
| 2132 | _ => sql_bail!("unknown FORMAT: {}", format), |
| 2133 | }) |
| 2134 | .transpose()?; |
| 2135 | |
| 2136 | match (&direction, &target) { |
| 2137 | (CopyDirection::To, CopyTarget::Stdout) => { |
| 2138 | if options.delimiter.is_some() { |
| 2139 | sql_bail!("COPY TO does not support DELIMITER option yet"); |
| 2140 | } |
| 2141 | if options.quote.is_some() { |
| 2142 | sql_bail!("COPY TO does not support QUOTE option yet"); |
| 2143 | } |
| 2144 | if options.escape.is_some() { |
| 2145 | sql_bail!("COPY TO does not support ESCAPE option yet"); |
| 2146 | } |
| 2147 | if options.null.is_some() { |
| 2148 | sql_bail!("COPY TO does not support NULL option yet"); |
| 2149 | } |
| 2150 | // `HEADER false` is the default and already honored; only an |
| 2151 | // enabled header is unimplemented. Silently accepting it would |
| 2152 | // make clients strip the first data row as a presumed header. |
| 2153 | if options.header == Some(true) { |
| 2154 | sql_bail!("COPY TO does not support HEADER option yet"); |
| 2155 | } |
| 2156 | match relation { |
| 2157 | CopyRelation::Named { .. } => sql_bail!("named with COPY TO STDOUT unsupported"), |
| 2158 | CopyRelation::Select(stmt) => Ok(plan_select( |
| 2159 | scx, |
| 2160 | stmt, |
| 2161 | &Params::empty(), |
| 2162 | Some(format.unwrap_or(CopyFormat::Text)), |
| 2163 | )?), |
| 2164 | CopyRelation::Subscribe(stmt) => Ok(plan_subscribe( |
| 2165 | scx, |
| 2166 | stmt, |
| 2167 | &Params::empty(), |
| 2168 | Some(format.unwrap_or(CopyFormat::Text)), |
| 2169 | )?), |
no test coverage detected