gajus / slonik

A Node.js PostgreSQL client with runtime and build time type safety, and composable SQL.
Other
4.56k stars 138 forks source link

When using multiple row insert with `unnest`, `boolean` data type results in an error whereas `bool` works #628

Closed romandvoskin closed 2 months ago

romandvoskin commented 2 months ago

Using the keyword boolean fails with unnest but bool works.

await pool.transaction(async (connection) => {
   await connection.query(sql.typeAlias("void")`
        CREATE TEMP TABLE test (b booleanl) ON COMMIT DROP;
      `);
        const types = ["boolean"]; // <--- This is the problem
        const values = [[true], [false]];
        await connection.query(sql.typeAlias("void")`
          INSERT INTO test (b)
          SELECT *
          FROM ${sql.unnest(values, types)}
        `);
      }
})

Expected Behavior

boolean is accepted by unnest

Current Behavior

An error occurs

error: type "boolean[]" does not exist

Possible Solution

Add support for boolean keyword

Steps to Reproduce

See above code

Notes

Even if this is not fixed I wanted to document the error for posterity.

gajus commented 2 months ago

That's expected https://github.com/gajus/slonik?tab=readme-ov-file#sqlarray-membertype