Support for Postgres's CREATE SERVER

This commit is contained in:
Sergey Olontsev 2025-06-30 08:14:00 +03:00
parent 50c605a471
commit 2e5f3562f0
No known key found for this signature in database
GPG key ID: 67DDC06CA52E8A39
5 changed files with 184 additions and 1 deletions

View file

@ -6231,3 +6231,75 @@ fn parse_ts_datatypes() {
_ => unreachable!(),
}
}
#[test]
fn parse_create_server() {
assert_eq!(
pg_and_generic().verified_stmt("CREATE SERVER myserver FOREIGN DATA WRAPPER postgres_fdw"),
Statement::CreateServer {
name: ObjectName::from(vec!["myserver".into()]),
if_not_exists: false,
server_type: None,
version: None,
fdw_name: ObjectName::from(vec!["postgres_fdw".into()]),
options: None,
}
);
assert_eq!(
pg_and_generic().verified_stmt("CREATE SERVER IF NOT EXISTS myserver TYPE 'server_type' VERSION 'server_version' FOREIGN DATA WRAPPER postgres_fdw"),
Statement::CreateServer {
name: ObjectName::from(vec!["myserver".into()]),
if_not_exists: true,
server_type: Some(Ident {
value: "server_type".to_string(),
quote_style: Some('\''),
span: Span::empty(),
}),
version: Some(Ident {
value: "server_version".to_string(),
quote_style: Some('\''),
span: Span::empty(),
}),
fdw_name: ObjectName::from(vec!["postgres_fdw".into()]),
options: None,
}
);
assert_eq!(
pg_and_generic().verified_stmt("CREATE SERVER myserver2 FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host 'foo', dbname 'foodb', port '5432')"),
Statement::CreateServer {
name: ObjectName::from(vec!["myserver2".into()]),
if_not_exists: false,
server_type: None,
version: None,
fdw_name: ObjectName::from(vec!["postgres_fdw".into()]),
options: Some(vec![
ServerOption {
key: "host".into(),
value: Ident {
value: "foo".to_string(),
quote_style: Some('\''),
span: Span::empty(),
},
},
ServerOption {
key: "dbname".into(),
value: Ident {
value: "foodb".to_string(),
quote_style: Some('\''),
span: Span::empty(),
},
},
ServerOption {
key: "port".into(),
value: Ident {
value: "5432".to_string(),
quote_style: Some('\''),
span: Span::empty(),
},
},
]),
}
)
}