Skip to content

Basic problems with generated SQL for Postgres #627

@MortenChristiansen

Description

@MortenChristiansen

I have a feeling that I'm missing something, but my experience with the PostgresCompiler is that it has several problems creating valid queries even for simple scenarios. There are things which seem so basic that I cannot be the first to run into them - hence the feeling that I am missing something. The queries were executed by manually taking the compiled sql and executing them with Dapper, if it makes any difference. I'm using version 2.4 of the library.

  1. When using query.WhereContains, the query string itself is not surrounded with 's which it must be. I updated the CompileBasicStringCondition implementation to change the switch statement to the following:
switch (x.Operator)
{
    case "starts":
        text2 = "'" + text2 + "%'";
        break;
    case "ends":
        text2 = "'%" + text2 + "'";
        break;
    case "contains":
        text2 = "'%" + text2 + "%'";
        break;
}
  1. When using query.WhereLike I had the same problem as in 1), but here the solution was just to prewrap my argument in single quotes at the call site. This is less of a big deal, but takes away from a feeling that the library "just works".

  2. When selecting columns, they are wrapped in "s. This is not valid, so I had to do the following in my compiler.

public override string WrapValue(string value) =>
    value;

I'm not sure if this has any influence on 1) and 2), but I don't think so since the quotation character is " which is not what is needed in those cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions