You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ReadModelSqlGenerator Column Prefix and Suffix - Not Used in Select Query #1002
I am using PostgreSQL read models and discovered an issue with the column names.
STR
I created all tables with double-quoted values for table and column names using FluentMigrator (this is the default FluentMigrator PostgreSQl configuration).
I registered PostgreSql readModels using ConfigurePostgreSql and UsePostgreSqlReadModel
I added [PostgreSqlReadModelIdentityColumn] attribute to ReadModel's property Id
AR
When working with read models I am receiving an error from PostgreSQL that column id does not exists
ER
Should work well with such configuration by default OR should be configured by registering custom ReadModelSqlGenerator:
sql=$"UPDATE {tableName} SET {updateColumns} WHERE {Configuration.ColumnQuotedIdentifierPrefix}{identityColumn}{Configuration.ColumnQuotedIdentifierSuffix} = @{identityColumn}{versionCheck}";
.
Also, there is a question, why columnQuotedIdentifierPrefix: "\"" and columnQuotedIdentifierSuffix: "\"" - not used by default for PostgreSql configuration?
We hope you are doing well. We noticed that this issue has not seen any activity in the past 90 days.
We consider this issue to be stale and will be closing it within the next seven days.
If you still require assistance with this issue, please feel free to reopen it or create a new issue.
CreateSelectSql currently ignores the configured column identifier quoting: it emits WHERE {identityColumn} = ... using the raw property name (Id, AggregateId, etc.) without prefix/suffix injection (Source/EventFlow.Sql/ReadModels/ReadModelSqlGenerator.cs:92-105). When PostgreSQL tables are created with double-quoted identifiers (e.g., "Id"), the generated SQL is lowered to id, triggering the reported column "id" does not exist.
The Postgres-specific generator deliberately sets columnQuotedIdentifierPrefix/Suffix to empty strings (Source/EventFlow.PostgreSql/ReadModels/PostgresReadModelSqlGenerator.cs:27-31) so that legacy schemas with unquoted, all-lowercase column names continue to work. Because CreateSelectSql disregards the configuration, providing a custom generator (as in the issue body) has no effect on SELECT statements, even though DELETE/UPDATE do honor the configuration.
Reproduction
Define a PostgreSQL read model with an identity property marked [PostgreSqlReadModelIdentityColumn] (e.g., Id).
Create the backing table via FluentMigrator (or any tooling) that emits quoted identifiers: CREATE TABLE "ReadModel-Example" ("Id" uuid PRIMARY KEY, ...);
Register the standard Postgres read model store via ConfigurePostgreSql().UsePostgreSqlReadModel<...>().
Execute any read-model fetch/update path; the generated SQL becomes SELECT * FROM "ReadModel-Example" WHERE Id = @EventFlowReadModelId, which PostgreSQL rewrites to id, producing 42703: column Id does not exist.
Fix Ideas
Quote identity columns in CreateSelectSql just like the other CRUD statements, e.g.
varquotedIdentity=$"{Configuration.ColumnQuotedIdentifierPrefix}{identityColumn}{Configuration.ColumnQuotedIdentifierSuffix}";sql=$"SELECT * FROM {tableName} WHERE {quotedIdentity} = @EventFlowReadModelId";
This makes custom configurations (including the issue reporter’s) effective without breaking existing schemas—because the default Postgres generator keeps prefix/suffix empty, nothing changes for today’s users.
Add a regression test alongside CreateSelectSql_ProducesCorrectSql (Source/EventFlow.Sql.Tests/UnitTests/ReadModels/ReadModelSqlGeneratorTests.cs:49-61) that covers a generator initialized with non-empty column quotes to ensure SELECT honors the configuration going forward.
On the default Postgres configuration
We keep columnQuotedIdentifierPrefix empty by default to preserve compatibility with the sample DDL and existing migrations that create unquoted lowercase columns. Enabling double quotes out of the box would immediately break those installations because WHERE "AggregateId" would no longer match aggregateid. With the SELECT bug fixed, teams that rely on quoted identifiers can simply override the generator configuration, while the default behavior remains backward compatible.
Activity
github-actions commentedon Nov 15, 2023
Hello there!
We hope you are doing well. We noticed that this issue has not seen any activity in the past 90 days.
We consider this issue to be stale and will be closing it within the next seven days.
If you still require assistance with this issue, please feel free to reopen it or create a new issue.
Thank you for your understanding and cooperation.
Best regards,
EventFlow
rasmus commentedon Oct 26, 2025
.analyze
github-actions commentedon Oct 26, 2025
Findings
CreateSelectSqlcurrently ignores the configured column identifier quoting: it emitsWHERE {identityColumn} = ...using the raw property name (Id,AggregateId, etc.) without prefix/suffix injection (Source/EventFlow.Sql/ReadModels/ReadModelSqlGenerator.cs:92-105). When PostgreSQL tables are created with double-quoted identifiers (e.g.,"Id"), the generated SQL is lowered toid, triggering the reportedcolumn "id" does not exist.columnQuotedIdentifierPrefix/Suffixto empty strings (Source/EventFlow.PostgreSql/ReadModels/PostgresReadModelSqlGenerator.cs:27-31) so that legacy schemas with unquoted, all-lowercase column names continue to work. BecauseCreateSelectSqldisregards the configuration, providing a custom generator (as in the issue body) has no effect on SELECT statements, even though DELETE/UPDATE do honor the configuration.Reproduction
[PostgreSqlReadModelIdentityColumn](e.g.,Id).CREATE TABLE "ReadModel-Example" ("Id" uuid PRIMARY KEY, ...);ConfigurePostgreSql().UsePostgreSqlReadModel<...>().SELECT * FROM "ReadModel-Example" WHERE Id = @EventFlowReadModelId, which PostgreSQL rewrites toid, producing42703: column Id does not exist.Fix Ideas
CreateSelectSqljust like the other CRUD statements, e.g.CreateSelectSql_ProducesCorrectSql(Source/EventFlow.Sql.Tests/UnitTests/ReadModels/ReadModelSqlGeneratorTests.cs:49-61) that covers a generator initialized with non-empty column quotes to ensure SELECT honors the configuration going forward.On the default Postgres configuration
columnQuotedIdentifierPrefixempty by default to preserve compatibility with the sample DDL and existing migrations that create unquoted lowercase columns. Enabling double quotes out of the box would immediately break those installations becauseWHERE "AggregateId"would no longer matchaggregateid. With the SELECT bug fixed, teams that rely on quoted identifiers can simply override the generator configuration, while the default behavior remains backward compatible.Your friendly neighborhood AI