Does `@vercel/postgres` support array columns?
Answered
Cape lion posted this in #help-forum
Cape lionOP
I have a posts table, which has an array column like so:
I inserted the value into the column:
Which appears fine, but whenever I
It gives the following output for
Is this intended? Is
ALTER TABLE posts
ADD tags varchar[] default array[]::varchar[];I inserted the value into the column:
UPDATE posts
SET tags = ARRAY['Miscellaneous']
WHERE id = 'my-first-post';Which appears fine, but whenever I
SELECT * with @vercel/postgres:export type BlogPost = {
id: string;
title: string;
subtitle: string;
content: string;
views: number;
tags: string[];
};
const { rows } = await sql<BlogPost>`SELECT * FROM posts`;It gives the following output for
rows:[
{
title: 'My First Post',
subtitle: 'This is my first blog post!',
content: '## It is kinda quiet in here...\\nWhat is next?',
views: 0,
id: 'my-first-post',
tags: '{Miscellaneous}'
}
]Is this intended? Is
tags not meant to be a string[] as it technically is in the Postgres table? Should I use an ORM if I want type "coercion" like this?Answered by Cape lion
Huh, I got it working now... not really sure what I did differently, but after inserting the data through my code instead of sending a query directly, it just works...
2 Replies
Cape lionOP
Instead, I could have a
tags table, and do some joining, but having an array column would be nice too... :PCape lionOP
Huh, I got it working now... not really sure what I did differently, but after inserting the data through my code instead of sending a query directly, it just works...
Answer