3
  import { sql } from '@vercel/postgres';
  const aliases= ['uncle', 'joe'];
  await sql`INSERT INTO USER (aliases) VALUES ${aliases}`;

USER would be defined like this

CREATE TABLE USER ( aliases text[]);

This code would give me an error : Argument of type 'string[]' is not assignable to parameter of type 'Primitive'.

0

1 Answer 1

1

You can stringify the array before making the insert, eg: const aliases = JSON.stringify([...]) then when you read simply parse the string const parseData = JSON.parse(aliases)

Sign up to request clarification or add additional context in comments.

2 Comments

I just added replace like this JSON.stringify(aliases).replace("[", "{").replace("]", "}") and it worked. Can you update your answer so I can accept it plz ?
This solution adds a string, not an array. Is there any way to add an array since arrays are part of the Primitive types ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.