postgresql returning id where sqlite works just fine
See original GitHub issueHello all,
i have a scenario where my dev environment works ok however i face problemas on staging/production.
here’s the faulty model:
const LembreteCatolico = Bookshelf.Model.extend({
tableName: "lembretecatolico"
});
And this table is created like this:
.createTable("lembretecatolico", (table) => {
table.integer("idlembrete").notNullable().references("lembrete.idlembrete");
table.integer("idcatolico").notNullable().references("catolico.idcatolico");
table.primary(["idlembrete", "idcatolico"]);
});
when running under sqlite, this express route works just fine:
router.post("/schedule/add", (req, res) => {
LembreteCatolico.forge(req.body).save().then((ret) => {
res.send(ret);
}).catch((err) => {
res.status(409).send("CONFLICT");
console.log(err);
});
});
however when running with postgres it raises the following error:
Relevant part is the query created:
error: insert into “lembretecatolico” (“idcatolico”, “idlembrete”) values ($1, $2) returning “id” - coluna “id” não existe
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
SQLite with insert returning not working as in PostgreSQL
Testing the recently welcome added "returning" clause for inserts with this query that does work in PostgreSQL but doesn't in SQLite: ...
Read more >PSQL `returning` statement returning Unit · Issue #2372 - GitHub
This is a first draft of what the generated code should look like for a mutator statement which has a RETURNING clause.
Read more >How to get RETURNING ID - postgresql - Stack Overflow
Use just plain INSERT ... RETURNING . And in Go use conn.Query to get the *sql.Rows (instead of *sql.Row [singular]). And then scan...
Read more >How to Use Flask-SQLAlchemy to Interact with Databases in a ...
It provides ways to interact with several database engines such as SQLite, MySQL, and PostgreSQL. It gives you access to the database's SQL...
Read more >Writing SQL that works on PostgreSQL, MySQL and SQLite
So REPLACE INTO basically either updates or inserts a new record. This works on both SQLite and MySQL, but not PostgreSQL. Since version...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sombriks After some research, I found the line responsible for the save, which call the knex builder, uses the
idAttribute
as returning value for the insert knex method. If you give it'*'
, it will works, but only for insertHello @sombriks You should override the
primaryKey
of the model as you did for thetableName