From a4d56ed563803fdc07f58065e0ba231bbc871bf6 Mon Sep 17 00:00:00 2001 From: gintil Date: Mon, 9 Dec 2024 09:10:00 -0500 Subject: [PATCH] Fix sql syntax error --- ...tioned-feed-article-field-store.service.ts | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/services/user-feeds/src/articles/partitioned-feed-article-field-store.service.ts b/services/user-feeds/src/articles/partitioned-feed-article-field-store.service.ts index 3f0d3c682..560891d38 100644 --- a/services/user-feeds/src/articles/partitioned-feed-article-field-store.service.ts +++ b/services/user-feeds/src/articles/partitioned-feed-article-field-store.service.ts @@ -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}`);