D
D
Denis Karimov2016-11-18 03:38:19
PostgreSQL
Denis Karimov, 2016-11-18 03:38:19

PostgreSQL. How to put JOINs into a subarray?

Hello. The bottom line is... let's say there is a categories table with columns ( id , alias , title ), and an articles table ( id , alias , title , text , category ), where category is dependent on the categories table by id . How to properly execute a query to get an object of this type:

{
    id: 1,
    alias: "testarticle",
    title: "Заголовок",
    text: "Тест записи"
    category: {
        id: 1,
        alias: "testcat"
        title: "Заголовок категории"
    }
}

For example, I know that in Django this order is issued by itself if you build a query through query builser, however, in nodeJS you have to write pure queries. No matter how much I read, everywhere I have to compose hemorrhoids by building a query in a query, however, I do not think that such a query will be well optimized. Are there other solutions?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question