mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-22 23:14:07 +00:00
Support SQLite CREATE VIRTUAL TABLE
(#209)
`CREATE VIRTUAL TABLE .. USING <module_name> (<module_args>)` https://www.sqlite.org/lang_createvtab.html
This commit is contained in:
parent
0c83e5d9e8
commit
a53f1d26ef
5 changed files with 73 additions and 4 deletions
|
@ -55,6 +55,7 @@ pub enum IsLateral {
|
|||
Lateral,
|
||||
NotLateral,
|
||||
}
|
||||
use crate::ast::Statement::CreateVirtualTable;
|
||||
use IsLateral::*;
|
||||
|
||||
impl From<TokenizerError> for ParserError {
|
||||
|
@ -986,16 +987,35 @@ impl Parser {
|
|||
self.parse_create_view()
|
||||
} else if self.parse_keyword(Keyword::EXTERNAL) {
|
||||
self.parse_create_external_table()
|
||||
} else if self.parse_keyword(Keyword::VIRTUAL) {
|
||||
self.parse_create_virtual_table()
|
||||
} else if self.parse_keyword(Keyword::SCHEMA) {
|
||||
self.parse_create_schema()
|
||||
} else {
|
||||
self.expected(
|
||||
"TABLE, VIEW, INDEX or SCHEMA after CREATE",
|
||||
self.peek_token(),
|
||||
)
|
||||
self.expected("an object type after CREATE", self.peek_token())
|
||||
}
|
||||
}
|
||||
|
||||
/// SQLite-specific `CREATE VIRTUAL TABLE`
|
||||
pub fn parse_create_virtual_table(&mut self) -> Result<Statement, ParserError> {
|
||||
self.expect_keyword(Keyword::TABLE)?;
|
||||
let if_not_exists = self.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]);
|
||||
let table_name = self.parse_object_name()?;
|
||||
self.expect_keyword(Keyword::USING)?;
|
||||
let module_name = self.parse_identifier()?;
|
||||
// SQLite docs note that module "arguments syntax is sufficiently
|
||||
// general that the arguments can be made to appear as column
|
||||
// definitions in a traditional CREATE TABLE statement", but
|
||||
// we don't implement that.
|
||||
let module_args = self.parse_parenthesized_column_list(Optional)?;
|
||||
Ok(CreateVirtualTable {
|
||||
name: table_name,
|
||||
if_not_exists,
|
||||
module_name,
|
||||
module_args,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn parse_create_schema(&mut self) -> Result<Statement, ParserError> {
|
||||
let schema_name = self.parse_object_name()?;
|
||||
Ok(Statement::CreateSchema { schema_name })
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue