Skip to content
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

Syntax error in migrations when using SQL keyword as property name #3583

Open
tomasherceg opened this issue Dec 9, 2024 · 3 comments
Open

Comments

@tomasherceg
Copy link

I am getting the following exception when I use property name, which is a keyword in SQL:

public class ResourceGroupDocument
{
    ...
    public int Order { get; set; }
}

Exception:

Npgsql.PostgresException (0x80004005): 42601: syntax error at or near "order"
    at Npgsql.Internal.NpgsqlConnector.ReadMessageLong(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
    at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
    at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
    at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
    at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
    at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
    at Npgsql.NpgsqlCommand.ExecuteNonQuery(Boolean async, CancellationToken cancellationToken)
    at Weasel.Postgresql.PostgresqlMigrator.executeDelta(SchemaMigration migration, DbConnection conn, AutoCreate autoCreate, IMigrationLogger logger, CancellationToken ct)

I'll try to look at the issue more closely in detail later and submit a PR.

@jeremydmiller
Copy link
Member

@tomasherceg The formatting changes would actually happen in the Weasel.Postgresql library. What version of whatever are you hitting this? @mysticmind did a similar fix I believe very recently.

@mysticmind
Copy link
Member

@jeremydmiller It was a fix for SQL Server to handle reserved keywords. We can do a similar fix for Postgres as well.

@mysticmind
Copy link
Member

mysticmind commented Dec 14, 2024

Added PR JasperFx/weasel#155 pertaining to handling of reserved keyword in table name and column names.

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

No branches or pull requests

3 participants