We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4ad6aa7 commit ea22597Copy full SHA for ea22597
libs/langchain-community/src/indexes/postgres.ts
@@ -136,7 +136,15 @@ export class PostgresRecordManager implements RecordManagerInterface {
136
.join(", ");
137
138
const query = `
139
- SELECT k, (key is not null) ex from unnest(ARRAY[${arrayPlaceholders}]) k left join ${this.finalTableName} on k=key and namespace = $1;
+ WITH ordered_keys AS (
140
+ SELECT * FROM unnest(ARRAY[${arrayPlaceholders}]) WITH ORDINALITY as t(key, o)
141
+ )
142
+ SELECT ok.key, (r.key IS NOT NULL) ex
143
+ FROM ordered_keys ok
144
+ LEFT JOIN ${this.finalTableName} r
145
+ ON r.key = ok.key
146
+ AND namespace = $1
147
+ ORDER BY ok.o;
148
`;
149
const res = await this.pool.query(query, [this.namespace, ...keys.flat()]);
150
return res.rows.map((row: { ex: boolean }) => row.ex);
0 commit comments