我正在执行对Postgre DB的查询,以获取早于特定日期的数据.

这是我的函数

async filesListToDelete(): Promise<any> {
  return await this.fileRepository.find({
    where: { last_modified: { $lt: '2018-11-15 10:41:30.746877' } },
  });
}

下面是我定义文件实体的方式:

export class File {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ nullable: false })
  idFonc: number;

  @Column({ nullable: false })
  version: number;

  @Column('varchar', { length: 100, nullable: false })
  filename: string;

  @Column({ nullable: true })
  last_modified: Date;

  @Column({ nullable: false })
  device: boolean;

  @ManyToOne(type => Type, { nullable: false })
  @JoinColumn({ referencedColumnName: 'id' })
  type: Type;

  @OneToMany(type => FileDevice, filedevice => filedevice.file)
  fileDevice: FileDevice[];
}

我收到这个错误

QueryFailedError: invalid input syntax for type timestamp: "{"$lt":"2018-11-15 10:41:30.746877"}"

推荐答案

你可以使用MoreThan,doc

async filesListToDelete(): Promise<any> {
  return await this.fileRepository.find({
   where: { 
       last_modified:  MoreThan('2018-11-15  10:41:30.746877') },
});}

Database相关问答推荐

使用存储过程从子表中删除数据

PostgreSQL 参数化 Order By / Limit in table 函数

502 是数据库错误的适当状态代码吗?

PostgreSQL - 按时间戳值分组?

Postgres pg_dump 每次都以不同的顺序转储数据库

SQL Select 用字符串替换整数

如何禁用 Django 查询缓存?

如果限制在本地机器上,最好使用 R 和 SQL

当可伸缩性无关紧要时,NoSQL 与 SQL

对百万行表,MySQL 的 LIKE 查询的性能怎样?

Meteor 如何执行数据库迁移?

C# 数据连接最佳实践?

为什么 HikariCP 推荐固定大小的池以获得更好的性能

单父实体的核心数据性能

如何通过 PHP 和 Linux 使用 pdo 连接到 mssql?

conflict serializable和conflict equivalent有什么区别?

Android 上的测试数据库:ProviderTestCase2 还是 RenamingDelegatingContext?

游戏中使用什么样的数据库?

如何修复 Postgres 上过时的 postmaster.pid 文件?

在一个查询中使用 group by 计算多列