question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Npgsql.PostgresException syntax error at or near "["

See original GitHub issue

Hello @JordanMarr,

in our project we are moving away from SQLServer to go to PostgreSQL.

I installed SqlHydra.Npgsql tool and generated the new database files.

I also installed Npgsql and removed the System.Data.SqlClient library.

My project is now compiling how when running the tests I get the following error:

System.AggregateException: One or more errors occurred. (42601: syntax error at or near "["

POSITION: 13)
 ---> Npgsql.PostgresException (0x80004005): 42601: syntax error at or near "["

POSITION: 13
   at Npgsql.Internal.NpgsqlConnector.<ReadMessage>g__ReadMessageLong|225_0(NpgsqlConnector connector, Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteNonQuery(Boolean async, CancellationToken cancellationToken)
  Exception data:
    Severity: ERROR
    SqlState: 42601
    MessageText: syntax error at or near "["
    Position: 13
    File: scan.l
    Line: 1176
    Routine: scanner_yyerror
   --- End of inner exception stack trace ---

I feel like the [ syntax error is because the generated SQL is for SQLServer instead of PostgreSQL.

The query which trigger the error is:

deleteAsync (Shared ctx) {
    for _ in table<dbo.EncounterForms> do
        deleteAll
}

Is there something I am missing? Is it possible to see the generated SQL by SQL Hydra to try understand the problem?

Issue Analytics

  • State:closed
  • Created 8 months ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
MangelMaximecommented, Jan 10, 2023

Oh…

I forgot to change SqlKata.Compilers.SqlServerCompiler() to SqlKata.Compilers.PostgresCompiler().

Got bitten once again by the openContext function 😅

0reactions
JordanMarrcommented, Jan 11, 2023

I haven’t tried that specifically, but i don’t see any reason why it wouldn’t work since the array types are not hardcoded.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PostgreSQL, Npgsql returning 42601: syntax error at or ...
I'm trying to use Npgsql and/or Dapper to query a table and I keep running into Npgsql.PostgresException 42601: syntax error at or near...
Read more >
42601: syntax error at or near "[" · Issue #404 · npgsql ...
Ran into this error message while trying to perform dotnet ef database ... Npgsql.PostgresException: 42601: syntax error at or near "[" #404.
Read more >
PostgreSQL error 42601- How we fix it
PostgreSQL error 42601 mainly occurs due to the syntax errors in the code. Proper syntax check and code correction will fix it up....
Read more >
Class PostgresException | Npgsql Documentation
Class PostgresException. The exception that is thrown when the PostgreSQL backend reports errors (e.g. query SQL issues, constraint violations).
Read more >
ERROR: syntax error at or near "END" [closed]
I thought it has to be with schema since you can see below the the table has a schema name of public so...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found