I want to get json out of my PostgreSQL database running version:
PostgreSQL 9.3.1 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3), 64-bit
The data I am trying to get is like:
{
"a" : "value",
"b" : {
"c" : "some_vaue here"
}
}
I am getting value from one table and some_value from some other table using join.
How can I achieve that?
Here is something similar, but I'm getting an error:
QUERY="
SELECT row_to_json(o) FROM (
SELECT oltl.id::text as ordinal,
oltl.nid as code,
oltl.description as description,
SELECT row_to_json(j)
FROM ( SELECT cilantag.tag as code ) AS j
from olt_languages oltl
inner join ci_language_tags cilantag
on oltl.ci_language_tag_id=cilantag.id
) AS o";
The error I am getting is
ERROR: syntax error at or near "SELECT" LINE 1: ...oltl.nid as code,oltl.description as description, SELECT row... ^ ` enter code here