sql >> Base de Datos >  >> RDS >> PostgreSQL

¿Cómo SELECCIONO datos de la tabla secundaria en PostgreSQL?

Una nueva función en PostgreSQL 9.2 pero no probé la consulta:

Sigo el tutorial de aquí .

select row_to_json(t)
from (
select ParentTable.parentTableFirstProp, (
select array_to_json(array_agg(row_to_json(child)))
  from (
    select childTableFirstProp
    from ChildTable
    where ChildTable.id=ParentTable.parentToChildReference
  ) child

  ) as parentToChildReference
from ParentTable
) t