Search code examples
postgresqlpg-promise

How to insert Comma-Separated Values in SELECT?


Example:

const columns = ['circle', 'square', 'triangle']

db.any('SELECT ($1:csv) FROM table', [columns])

But, unfortunately, this option gives an error - operator does not exist: integer[] @> text[]


Solution

  • If these are actually column names that you want to select:

    const columns = ['circle', 'square', 'triangle'];
    

    then the correct syntax is:

    db.any('SELECT $1:name FROM table', [columns])
    

    as per the SQL Names documentation ;)