question-mark
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.

Joins with overlapping column names, nested results

See original GitHub issue

@brianc https://github.com/felixge/node-mysql/#joins-with-overlapping-column-names It is possible to have a similar functionality in node-postgres? For example:

var config = {
  text: '...',
  values: ['...'],
  nestTables: true
};
client.query(config, function(res) {
  res.rows[0].tableA.id;
  res.rows[0].tableB.id;
});

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

12reactions
nstepiencommented, Feb 21, 2015

@brianc A friend and I played around with postgres, and it actually is possible to have nested tables in pg, for example:

let text = `SELECT to_json(a.*) AS table1, to_json(b.*) AS table2
FROM some_table a
LEFT JOIN another_table b ON a.id = b.id`;
client.query(text, function(res) {
  // ...
});

With this all rows will be structured as such:

{ table1: { ... },
  table2: { ... } }
7reactions
Offirmocommented, Sep 24, 2019

@brianc thanks mate! Your solution is the only one with 100% benefits!

For fellow googlers, this gives in knex:

return knex
	.select(knex.raw('row_to_json("users__netlify".*) AS "users__netlify", row_to_json("users".*) AS "users"')).from('users')
	.fullOuterJoin('users__netlify', {'users.id': 'users__netlify.user_id'})
	.where('users__netlify.own_id', netlify_id)
	.then(result => {
		console.log('outer join result', result)
	})
Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Escaping Queries with Options parameter for Joins ...
has an option for overlapping column names in table joins that looks like this: var options = {sql: '...', nestTables: true}; connection.
Read more >
Merging 2 Queries with Overlapping Data - Microsoft Power BI ...
Solved: I have two queries that I'd like to merge together. They have the same columns. The problem is that 1 query has...
Read more >
Configuring how Relationship Joins
Overlapping Foreign Keys¶. A rare scenario can arise when composite foreign keys are used, such that a single column may be the subject...
Read more >
Working with Joins - Snowflake Documentation
The two joined tables usually contain one or more columns in common so that the rows in one table can be associated with...
Read more >
Join Multiple Tool | Alteryx Help
Select and Deselect Fields/Columns ... To include a column in the dataset, check the check box to the left of the column name....
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found