K
Kysely•2y ago
Nil

insert data into a table that has id of type bigserial

I created a table that has id(bigserial), cognitoId(varchar), subaccountInfo(json), I'm trying like this:
const obj = [{
nome: "nil",
sobrenome: "kuro"
}]
const json = JSON.stringify(obj)
console.log(json)
const responseDb = await db
.withSchema("schemaName")
.insertInto('administrator')
.values({
"cognitoId": "nil",
"subaccountInfo": json
})
.execute()
const obj = [{
nome: "nil",
sobrenome: "kuro"
}]
const json = JSON.stringify(obj)
console.log(json)
const responseDb = await db
.withSchema("schemaName")
.insertInto('administrator')
.values({
"cognitoId": "nil",
"subaccountInfo": json
})
.execute()
But I can't record anything, I don't know where I'm going wrong...
3 Replies
Igal
Igal•2y ago
Hey 👋 What dialect are you using? Do you get any errors?
Nil
NilOP•2y ago
Hey, I found the problem, I had to specify the type in the json declaration, like this:
const obj = {
nome: "nil",
sobrenome: "kuro"
}
const json = JSON.stringify(obj)
console.log(json)
const responseDb = await db
.withSchema("dukeRecurrency")
.insertInto('administrator')
.values({
"cognitoId": "nil",
"asaasSubaccountInfo": sql`${json}::json`
})
.execute()
const obj = {
nome: "nil",
sobrenome: "kuro"
}
const json = JSON.stringify(obj)
console.log(json)
const responseDb = await db
.withSchema("dukeRecurrency")
.insertInto('administrator')
.values({
"cognitoId": "nil",
"asaasSubaccountInfo": sql`${json}::json`
})
.execute()
Igal
Igal•2y ago
Good catch! we might need to hint at this in the docs, common postgres question
Want results from more Discord servers?
Add your server