Skip to content

Commit

Permalink
Fix sql syntax error
Browse files Browse the repository at this point in the history
  • Loading branch information
synzen committed Dec 9, 2024
1 parent 332dfb9 commit a4d56ed
Showing 1 changed file with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,20 @@ export class PartitionedFeedArticleFieldStoreService {
const temporaryTableName = `current_article_ids_${feedId}`;
const sql =
`CREATE TEMP TABLE ${temporaryTableName} AS` +
` SELECT * FROM (VALUES ${ids.map(() => "(?)").join(", ")}) AS t(id)` +
` SELECT field_hashed_value` +
` FROM ${this.TABLE_NAME}` +
` INNER JOIN ${temporaryTableName} t ON (field_hashed_value = t.id)` +
` WHERE ${
olderThanOneMonth ? `created_at <= ?` : `created_at > ?`
} AND feed_id = ? AND field_name = 'id'`;

const result = await this.connection.execute(sql, [
...ids,
oneMonthAgo,
feedId,
]);
` SELECT * FROM (VALUES ${ids.map(() => "(?)").join(", ")}) AS t(id)`;

await this.connection.execute(sql, ids);

const result = await this.connection.execute(
`SELECT field_hashed_value` +
` FROM ${this.TABLE_NAME}` +
` INNER JOIN ${temporaryTableName} t ON (field_hashed_value = t.id)` +
` WHERE ${
olderThanOneMonth ? `created_at <= ?` : `created_at > ?`
} AND feed_id = ? AND field_name = 'id'` +
``,
[oneMonthAgo, feedId]
);

await this.connection.execute(`DROP TABLE ${temporaryTableName}`);

Expand Down

0 comments on commit a4d56ed

Please sign in to comment.