-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
I'm using pg v8.12.0, and I'm noticing that in some cases where I'm executing queries a timestamp (with time zone) that's expected to have a value always returns NULL.
The error manifests when I run a large SELECT * FROM table WHERE id in ('about', 'onehundred', 'ids');
query. If I pick one id out of the array and use pg
to run that same query again with only one element in the array, I get the timestamp as expected. I also ran this same one-hundred-elem-array query directly against Postgres and could not reproduce this issue, so it seems to be solely the fault of pg
. Any ideas what might be happening?
Here's how I'm using pg
for reference:
declare namespace DB {
class User {
email: string;
email_verified: boolean;
password: string;
attempt_count: number;
batch_id?: number;
uploaded_at?: Date; // This timestamptz always returns a value
job_id?: string;
linked_at?: Date; // This one never does
}
}
...
export async function executeQuery<O, I = DB.User>(
pool: pg.Pool,
queryString: string,
transformFn?: (e: I) => O
): Promise<O[]> {
const client = await pool.connect();
try {
const { rows } = await client.query(queryString);
if (transformFn) {
return rows.map(transformFn);
}
return rows;
} catch (err: any) {
logError(err);
throw err;
} finally {
client.release();
}
}
// USAGE:
await executeInexpensiveQuery(
pool,
`SELECT * FROM upload_data WHERE id IN (${userIds.map(id => `'${id}'`).join(',')});`,
)
I know the docs say to not inline those parameters but none of this is injectable. Still, I can try the prescribed way and report back.