Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

83
Views
SQL insert array of string - issues with .join(', ')

Currently I create a string with JavaScript that is used as a SQL query. It reads a number of rows from an Excel sheet and then creates the SQL query by combining all those datapoints with .join(','). I want to add added a column that is a list of tags.

It’s a comma separated array. When my string gets .joined(',')ed it just becomes a string.

Technically its still an array because its being added to my SQL query string as ARRAY['list, of, things'] but I need it to be in my SQL query string as ARRAY['list', 'of', 'things']. Any way to prevent this?

Snip it of code. company[3] is passed in as an array of strings:

const tagsPresent = company[3] !== null;

return format(
        `(%L, %L, ${
          tagsPresent ? `'{${company[3]}}'` : 'NULL::text[]'
          // I've also tried 'ARRAY[${company[3]}]' and ARRAY['+ company[3] +']

        })`,
        company[1],
        company[2]
      );
    })
    .join(', ');
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I was able to solve this by using a map.

${
          tagsPresent
            ? `ARRAY[${company[3]
                .split(',')
                .map((tag) => "'" + tag + "'")
                .toString()}]`
            : 'NULL::text[]'
        })
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!