Search code examples
node.jstypescriptpostgresqltypeorm

Getting an error when trying to use postgres typeorm Raw method


can anyone help me with this?

I'm having a error when trying to search in postgres with typeorm. I'm trying to pass a Raw where, but I'm getting the following error:

{
  "error": "column \"mm\" does not exist"
}

This is my code where I use Raw:

const appointments = await this.ormRepository.find({
    where: {
        date: Raw(
            dateFieldName =>
            `to_char(${dateFieldName}, MM-YYYY) = '${parsedMonth}-${year}'`,
        ),
    },
});

Thanks so much!


Solution

  • You have a typo: you've told Postgres that MM is a column (thus the error). Instead of MM-YYYY, use 'MM-YYYY'.