Skip to content

Support for Postgres's CREATE SERVER #1914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

solontsev
Copy link
Contributor

Closes #1814

@solontsev solontsev marked this pull request as ready for review June 30, 2025 05:23
@@ -4662,6 +4662,10 @@ impl<'a> Parser<'a> {
self.parse_create_procedure(or_alter)
} else if self.parse_keyword(Keyword::CONNECTOR) {
self.parse_create_connector()
} else if self.parse_keyword(Keyword::SERVER)
&& dialect_of!(self is PostgreSqlDialect | GenericDialect)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
&& dialect_of!(self is PostgreSqlDialect | GenericDialect)

I think it should be fine to let the parser be permissive and accept this statement whenever it shows up

#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct ServerOption {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub struct ServerOption {
pub struct CreateServerOption {

/// CREATE SERVER
/// ```
/// See [PostgreSQL](https://www.postgresql.org/docs/current/sql-createserver.html)
CreateServer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For new statements we're moving away from using anonymous structs, here can we introduce a dedicated struct for this statement?

CreateServer(CreateServerStatement)

See Statement::Raise as an example

if_not_exists: bool,
server_type: Option<Ident>,
version: Option<Ident>,
fdw_name: ObjectName,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to something more descriptive e.g. explicitly foreign_data_wrapper?

Comment on lines +15813 to +15820
/// ```sql
/// CREATE SERVER [ IF NOT EXISTS ] server_name [ TYPE 'server_type' ] [ VERSION 'server_version' ]
/// FOREIGN DATA WRAPPER fdw_name
/// [ OPTIONS ( option 'value' [, ... ] ) ]
/// ```
///
/// [PostgreSQL Documentation](https://www.postgresql.org/docs/current/sql-createserver.html)
pub fn parse_pg_create_server(&mut self) -> Result<Statement, ParserError> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// ```sql
/// CREATE SERVER [ IF NOT EXISTS ] server_name [ TYPE 'server_type' ] [ VERSION 'server_version' ]
/// FOREIGN DATA WRAPPER fdw_name
/// [ OPTIONS ( option 'value' [, ... ] ) ]
/// ```
///
/// [PostgreSQL Documentation](https://www.postgresql.org/docs/current/sql-createserver.html)
pub fn parse_pg_create_server(&mut self) -> Result<Statement, ParserError> {
/// Parse a `CREATE SERVER` statement.
///
/// See [Statement::CreateServer]
pub fn parse_pg_create_server(&mut self) -> Result<Statement, ParserError> {

I think we can do something like this to avoid duplicating the comments. The syntax we can skip entirely since that should be covered by the doc link if the reader requires further context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Postgres CREATE SERVER can't be parsed
2 participants