如何在 SELECT 中插入逗号分隔值?

How to insert Comma-Separated Values in SELECT?

示例:

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

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

但是,不幸的是,这个选项给出了一个错误——operator does not exist: integer[] @> text[]

如果这些实际上是您想要的列名select:

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

那么正确的语法是:

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

根据 SQL Names 文档 ;)