postgres icon indicating copy to clipboard operation
postgres copied to clipboard

Unable to query structured data

Open mnunezdm opened this issue 1 year ago • 0 comments

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
  `

mnunezdm avatar Jun 21 '24 09:06 mnunezdm