porsager / postgres

Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare
The Unlicense
7.03k stars 255 forks source link

Dot and Periods can't be used as values #910

Closed Ximaz closed 3 days ago

Ximaz commented 3 days ago

Hi there.

I'm trying to select a row where and email can include multiple dots (or period).

Here is my request :

await sql<User[]>`SELECT ${sql(cols)} FROM users WHERE ${sql(fieldName)} = ${sql(fieldValue)} LIMIT 1`

Where, at runtime :

Here is my error :

PostgresError: cross-database references are not implemented: a.b.c@d.com
    at ErrorResponse (file:///<project>/node_modules/postgres/src/connection.js:788:26)
    at handle (file:///<project>/node_modules/postgres/src/connection.js:474:6)
    at Socket.data (file:///<project>/node_modules/postgres/src/connection.js:315:9)
    at Socket.emit (node:events:519:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at TCP.onStreamRead (node:internal/stream_base_commons:191:23)
    at cachedError (file:///<project>/node_modules/postgres/src/query.js:170:23)
    at new Query (file:///<project>/node_modules/postgres/src/query.js:36:24)
    at sql (file:///<project>/node_modules/postgres/src/index.js:113:11)
    at Object.retrieveUserBy (file:///<project>/build/models/Users.js:44:27) {
  severity_local: 'ERROR',
  severity: 'ERROR',
  code: '42P01',
  position: '40',
  file: 'parse_relation.c',
  line: '3657',
  routine: 'errorMissingRTE'

Here is an other error for less dots :

PostgresError: missing FROM-clause entry for table "b@d"
    at ErrorResponse (file:///<project_path>/node_modules/postgres/src/connection.js:788:26)
    at handle (file:///<project_path>/node_modules/postgres/src/connection.js:474:6)
    at Socket.data (file:///<project_path>/node_modules/postgres/src/connection.js:315:9)
    at Socket.emit (node:events:519:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at TCP.onStreamRead (node:internal/stream_base_commons:191:23)
    at cachedError (file:///<project_path>/node_modules/postgres/src/query.js:170:23)
    at new Query (file:///<project_path>/node_modules/postgres/src/query.js:36:24)
    at sql (file:///<project_path>/node_modules/postgres/src/index.js:113:11)
    at Object.retrieveUserBy (file:///<project_path>/build/models/Users.js:44:27) {
  severity_local: 'ERROR',
  severity: 'ERROR',
  code: '42P01',
  position: '40',
  file: 'parse_relation.c',
  line: '3657',
  routine: 'errorMissingRTE'

I'd like to add that I had no issue when inserting such a row, where the email field included 2 dots.

porsager commented 3 days ago

Dont' put values inside sql()

await sql SELECT ${ sql(cols) } FROM users WHERE ${ sql(fieldName) } = ${ fieldValue } LIMIT 1