Changing a column name completely breaks the queries

I went back and forth multiple times now and this is really weird. So when using the following schema and queries everything works as expected:
export const habitStats = pgTable(
"habit_stats",
{
id: serial("id").primaryKey(),
habitId: integer("habit_id")
.notNull()
.references(() => habits.id),
profileId: integer("profile_id")
.notNull()
.references(() => profiles.id),
completed: timestamp("completed", {
precision: 4,
withTimezone: true,
})
.array()
.default(sql`array[current_timestamp]`),
updatedAt: date("updated_at").defaultNow(), // this is set every time that habit is completed
},
(t) => ({
unq: unique().on(t.habitId, t.profileId),
}),
);
export const habitStats = pgTable(
"habit_stats",
{
id: serial("id").primaryKey(),
habitId: integer("habit_id")
.notNull()
.references(() => habits.id),
profileId: integer("profile_id")
.notNull()
.references(() => profiles.id),
completed: timestamp("completed", {
precision: 4,
withTimezone: true,
})
.array()
.default(sql`array[current_timestamp]`),
updatedAt: date("updated_at").defaultNow(), // this is set every time that habit is completed
},
(t) => ({
unq: unique().on(t.habitId, t.profileId),
}),
);
Upsert query
const query = sql`insert into
habit_stats (habit_id, profile_id)
values
(${body.habitId}, ${body.profileId}) on conflict (habit_id, profile_id)
do
update
set
completed = current_timestamp || habit_stats.completed,
updated_at = current_date
where
habit_stats.updated_at is null or
fate (habit_stats.updated_at) != current_date;`;
const query = sql`insert into
habit_stats (habit_id, profile_id)
values
(${body.habitId}, ${body.profileId}) on conflict (habit_id, profile_id)
do
update
set
completed = current_timestamp || habit_stats.completed,
updated_at = current_date
where
habit_stats.updated_at is null or
fate (habit_stats.updated_at) != current_date;`;
Reset query
const query = sql`update habit_stats set completed = completed[2:], updated_at = null;`;
const query = sql`update habit_stats set completed = completed[2:], updated_at = null;`;
when changing updated_at to completed_at while keeping everything else the same, I am getting the following error:
{
"name": "PostgresError",
"severity_local": "ERROR",
"severity": "ERROR",
"code": "42601",
"position": "336",
"file": "scan.l",
"originalLine": 27,
"originalColumn": 10,
"routine": "scanner_yyerror"
}
{
"name": "PostgresError",
"severity_local": "ERROR",
"severity": "ERROR",
"code": "42601",
"position": "336",
"file": "scan.l",
"originalLine": 27,
"originalColumn": 10,
"routine": "scanner_yyerror"
}
If I revert back to updatedAt and push the schema again, everything works fine... What am I missing here?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server