porsager / porsager/postgres

Unable to query structured data

Open
#900 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
8.7k
Forks
374
Avg merge
11d 16h
Merged PRs (30d)
1

Description

Hello!

I'm having problems when accessing / filtering on / ordering by I'm able to query with a hardcoded query from a file or using the unsafe method, but... when trying to use it dynamically, I'm not able to write the correct code, I have looked into the documentation but I did not find anything

select
  identityMap['contactid'].id,
  segmentmembership['ups']['06e0ac99-d525-492b-8a34-c6a4f09d6b6e'].lastQualificationTime,
  segmentmembership['ups']['06e0ac99-d525-492b-8a34-c6a4f09d6b6e'].status
from
  profile_snapshot_export_fdcfa371_e04e_4206_bcf0_a07ce88ed172
where
  segmentmembership['ups']['06e0ac99-d525-492b-8a34-c6a4f09d6b6e'].status != ''
order by segmentmembership['ups']['06e0ac99-d525-492b-8a34-c6a4f09d6b6e'].lastQualificationTime desc

This is running code but its using the unsafe method...

const response: IdentityMap[] = await sql`
  select
    ${sql.unsafe(
      [
        `identityMap['contactid'].id`,
        `segmentmembership['ups']['${segmentId}'].lastQualificationTime`,
        `segmentmembership['ups']['${segmentId}'].status`,
      ].join(','),
    )}
  from
    ${sql(TABLE_BY_ENV[argv.entorno])}
  where
    ${sql.unsafe(`segmentmembership['ups']['${segmentId}'].status`)} != ''
  order by ${sql.unsafe(
    `segmentmembership['ups']['${segmentId}'].lastQualificationTime`,
  )} desc
  `

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository file, test, or entry point is named. Start by reproducing the tagged-template query with the dynamic JSON paths, then inspect the client documentation for safe interpolation of identifiers and expressions; done means the dynamic query works without unsafe interpolation.

Written by the indexing model from the issue text.

Assessment

Tech stack
nodejs, postgresql, typescript
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.