postgresql/typeorm/nestjs
我报告使用typeorm插入数据时出错,主要是因为rangetype没有转换为字符串
@Entity()
export class Test {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column('numrange', { array: true })
price: number[];
}
this.entityRepository.save({
price: [100,200]
})
logger: INSERT INTO "test" ( "id", "price", ) VALUES ( DEFAULT, $1 ) RETURNING "id" -- PARAMETERS: [[100,200]]
postgresql: ERROR: syntax error at or near "["
在pg驱动程序中,它是
pool.query(
`
INSERT INTO test
(title,numbers_range)
VALUES ($1,$2)
`,
["test", JSON.stringify([100, 200])],
);
PS:
[100020]包括200
[1000200(不包括200
OR
pool.query(
`
INSERT INTO test
(title,numbers_range)
VALUES ($1,$2)
`,
["test", "[100,200)"],
);
在打字形式中,它可以是
this.entityRepository.save({
price: JSON.stringify([100,200])
})
或
this.entityRepository.save({
price: "[100,200)"
})
来自文档https://www.postgresql.org/docs/current/rangetypes.html#RANGETYPES-索引
CREATE TABLE reservation (room int, during tsrange);
INSERT INTO reservation VALUES
(1108, '[2010-01-01 14:30, 2010-01-01 15:30)');