Skip to content

Instantly share code, notes, and snippets.

@ff6347
Last active March 21, 2019 06:21
Show Gist options
  • Select an option

  • Save ff6347/9c608906c52fb37ad4e76386c502d072 to your computer and use it in GitHub Desktop.

Select an option

Save ff6347/9c608906c52fb37ad4e76386c502d072 to your computer and use it in GitHub Desktop.

This is the gist for the so question https://stackoverflow.com/questions/55240553/what-is-wrong-with-the-parameters-in-my-typeorm-where-clause-for-the-querybuilde

The original error is part of this project/file https://github.com/technologiestiftung/flusshygiene-postgres-api/blob/master/src/lib/repositories/BathingspotRepository.ts#L10

This is the error in isolation https://github.com/fabianmoronzirfas/typeorm-issue-qb

Unfortuantely in isolation adding "" around the query string with paramterers works. In production not.

Failing query: SELECT "bathingspot"."id" AS "bathingspot_id", "bathingspot"."name" AS "bathingspot_name", "bathingspot"."isPublic" AS "bathingspot_isPublic", "bathingspot"."apiEndpoints" AS "bathingspot_apiEndpoints", "bathingspot"."state" AS "bathingspot_state", "bathingspot"."location" AS "bathingspot_location", "bathingspot"."latitde" AS "bathingspot_latitde", "bathingspot"."longitude" AS "bathingspot_longitude", "bathingspot"."elevation" AS "bathingspot_elevation", "bathingspot"."userId" AS "bathingspot_userId" FROM "bathingspot" "bathingspot" WHERE bathingspot.userId = $1 AND "bathingspot"."id" = $2
{ QueryFailedError: column bathingspot.userid does not exist
at new QueryFailedError (/Users/icke/tmp/typeorm-issue-qb/src/error/QueryFailedError.ts:9:9)
at Query.callback (/Users/icke/tmp/typeorm-issue-qb/src/driver/postgres/PostgresQueryRunner.ts:176:30)
at Query.handleError (/Users/icke/tmp/typeorm-issue-qb/node_modules/pg/lib/query.js:142:17)
at Connection.connectedErrorMessageHandler (/Users/icke/tmp/typeorm-issue-qb/node_modules/pg/lib/client.js:183:17)
at Connection.emit (events.js:197:13)
at Connection.EventEmitter.emit (domain.js:439:20)
at Socket.<anonymous> (/Users/icke/tmp/typeorm-issue-qb/node_modules/pg/lib/connection.js:125:12)
at Socket.emit (events.js:197:13)
at Socket.EventEmitter.emit (domain.js:439:20)
at addChunk (_stream_readable.js:288:12)
message: 'column bathingspot.userid does not exist',
name: 'QueryFailedError',
length: 182,
severity: 'ERROR',
code: '42703',
detail: undefined,
hint:
'Perhaps you meant to reference the column "bathingspot.userId".',
position: '546',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_relation.c',
line: '3294',
routine: 'errorMissingColumn',
query:
'SELECT "bathingspot"."id" AS "bathingspot_id", "bathingspot"."name" AS "bathingspot_name", "bathingspot"."isPublic" AS "bathingspot_isPublic", "bathingspot"."apiEndpoints" AS "bathingspot_apiEndpoints", "bathingspot"."state" AS "bathingspot_state", "bathingspot"."location" AS "bathingspot_location", "bathingspot"."latitde" AS "bathingspot_latitde", "bathingspot"."longitude" AS "bathingspot_longitude", "bathingspot"."elevation" AS "bathingspot_elevation", "bathingspot"."userId" AS "bathingspot_userId" FROM "bathingspot" "bathingspot" WHERE bathingspot.userId = $1 AND "bathingspot"."id" = $2',
parameters: [ 1, 1 ] }
const sqlQueryFail = this.createQueryBuilder('bathingspot')
    // .where(`"bathingspot"."userId" = ${userId}`)
    .where('bathingspot.userId = :id', {id: userId})
    .andWhere('bathingspot.id = :id', {id: spotId}).getSql();
    console.log('failing query 1', sqlQueryFail);

failing query

SELECT "bathingspot"."id" AS "bathingspot_id", "bathingspot"."name" AS "bathingspot_name", "bathingspot"."isPublic" AS "bathingspot_isPublic", "bathingspot"."apiEndpoints" AS "bathingspot_apiEndpoints", "bathingspot"."state" AS "bathingspot_state", "bathingspot"."location" AS "bathingspot_location", "bathingspot"."latitude" AS "bathingspot_latitude", "bathingspot"."longitude" AS "bathingspot_longitude", "bathingspot"."elevation" AS "bathingspot_elevation", "bathingspot"."userId" AS "bathingspot_userId", "bathingspot"."regionId" AS "bathingspot_regionId" FROM "bathingspot" "bathingspot" WHERE "bathingspot"."userId" = $1 AND "bathingspot"."id" = $2
const sqlQueryFail = this.createQueryBuilder('bathingspot')
    .where(`"bathingspot"."userId" = ${userId}`)
    //.where('bathingspot.userId = :id', {id: userId})
    .andWhere('bathingspot.id = :id', {id: spotId}).getSql();
    console.log('failing query 1', sqlQueryFail);

working query

SELECT "bathingspot"."id" AS "bathingspot_id", "bathingspot"."name" AS "bathingspot_name", "bathingspot"."isPublic" AS "bathingspot_isPublic", "bathingspot"."apiEndpoints" AS "bathingspot_apiEndpoints", "bathingspot"."state" AS "bathingspot_state", "bathingspot"."location" AS "bathingspot_location", "bathingspot"."latitude" AS "bathingspot_latitude", "bathingspot"."longitude" AS "bathingspot_longitude", "bathingspot"."elevation" AS "bathingspot_elevation", "bathingspot"."userId" AS "bathingspot_userId", "bathingspot"."regionId" AS "bathingspot_regionId" FROM "bathingspot" "bathingspot" WHERE "bathingspot"."userId" = 2 AND "bathingspot"."id" = $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment