N
Neon2y ago
genetic-orange

Error in POST function: NeonDbError: value too long for type character varying(200)

This is what I am trying to do:
const chat_id = await db.insert(chats).values({ fileKey: file_key, pdfname: file_name, pdfUrl: getfileurl(file_key), userId, }) .returning({ insertedId: chats.id }); and this is my schema export const chats = pgTable('chats', { id: serial('id').primaryKey(), pdfname : text('pdf_name').notNull(), pdfUrl : text('pdf_url').notNull(), createdAt : timestamp('created_at').notNull().defaultNow(), userId: text('user_id').notNull(), fileKey : text('file_key').notNull(), }); what should I do to fix this?
7 Replies
clever-tan
clever-tan2y ago
Hey! This is Stephen from twitter
genetic-orange
genetic-orangeOP2y ago
Hi! I am sarthak
clever-tan
clever-tan2y ago
Is the userid field set to 200 length?
genetic-orange
genetic-orangeOP2y ago
I just chaged that also to text to check iff that's the problem but it doesnt seem like it it was previously set to 255 length
clever-tan
clever-tan2y ago
And if you log out the fields before insert , there aren’t any that are longer than expected?
genetic-orange
genetic-orangeOP2y ago
yes as per example there Length of file_key: 34 Length of file_name: 26
clever-tan
clever-tan2y ago
hmm, can you verify the table structure. Just to make sure that types are set. something like -
SELECT
column_name,
data_type,
character_maximum_length,
is_nullable,
column_default
FROM
information_schema.columns
WHERE
table_name = '<chats-table-name>';
SELECT
column_name,
data_type,
character_maximum_length,
is_nullable,
column_default
FROM
information_schema.columns
WHERE
table_name = '<chats-table-name>';
or using \d <table-name> from psql Just following up here - we were able to get this resolved offline. The userid was longer than expected and violating the column length.

Did you find this page helpful?