Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use on_duplicate_ignore with subselect?

See original GitHub issue

In PostgreSQL, when attempting to do something like the following:

customers, customers_backup = Tables('customers', 'customers_backup')

q = Query.into(customers_backup).columns('id', 'fname', 'lname')
    .from_(customers).select(, customers.fname, customers.lname).on_duplicate_ignore()

I get the error TypeError: 'Field' object is not callable. Am I doing something wrong or is this not yet supported?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

ivanvenosdelcommented, May 4, 2020

Great! I will try it out and get back to you.

airtonzanoncommented, Apr 30, 2020

Indeed, on MySQL it works:

q = MySQLQuery.into(customers_backup).columns('id', 'fname', 'lname'). \
from_(customers).select(, customers.fname, customers.lname).on_duplicate_key_ignore()


INSERT INTO `customers_backup` (`id`,`fname`,`lname`) SELECT `id`,`fname`,`lname` FROM `customers` ON DUPLICATE KEY IGNORE

This is not implemented for PostgreSQL dialect. What would be the right output for PostgreSQL? With the right output I can take a look and implement that for PostgreSQL as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mysql on duplicate key update + sub query - Stack Overflow
INSERT INTO new_table (date,record_id,data_field,value) SELECT date, record_id, data_field, SUM(other_table.value) as value FROM old_table JOIN ...
Read more >
Deduplicate Data Using Having with Subquery
I'm now trying to remove the duplicate records, then add a constraint to block this going forward. I have this query: SELECT count(*)...
Read more > INSERT ... ON DUPLICATE KEY UPDATE Statement
INSERT INTO t1 SELECT c, c+d FROM t2 ON DUPLICATE KEY UPDATE b = VALUES(b);. You can eliminate such warnings by using a...
Read more >
Subqueries (SQL Server) - Microsoft Learn
A subquery is a query that is nested inside a SELECT , INSERT , UPDATE , or DELETE statement, or inside another subquery....
Read more >
MySQL Subquery - MySQL Tutorial
In this example, both outer query and correlated subquery reference the same products table. Therefore, we need to use a table alias p1...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found