how to convert this sql "select id, 3 as level from t_lps_factory“ to postgrest? #3170
-
Environment
Description of issueI want use postgrest to implement this sql: select id, 1 as level from t_lps_factory; |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
PostgREST won't let you select extra columns that do not exist in the table ( |
Beta Was this translation helpful? Give feedback.
-
Thank reply,but i use multiple relationship table to create tree data struct dynamic, so, the sql is create by funciton,eg: const tableRecurve = (level: number, tabs: string[]) => {
let sqlStr = '';
let lvl = level + 1;
if(tabs.length === 1) {
sqlStr += `children:${tabs[0]}(*,level-${lvl}:id)`;
}else{
const temp = tabs.filter((it, id) => id !== 0);
sqlStr = `children:${tabs[0]}(*,level-${lvl}:id,${tableRecurve(lvl, temp)})`;
}
return sqlStr;
}
const temp = tabs.filter((it, idx) => idx !== 0);
const sql = tableRecurve(1, temp);
let sqlStr = tabs[0];
sqlStr += `?select=*,level-${1}:id,`;
sqlStr += sql; result is below, i use id placehoder the 'level', parse level-2 to level: 2 in function:
|
Beta Was this translation helpful? Give feedback.
-
thanks reply but level-1, level-2...is not i wanted.this field is tree's depth.so i hope to get result is: leve:1, level: 2. so, i must process the result by extra parse function to parse level-1:id to level:1. |
Beta Was this translation helpful? Give feedback.
That resulting query looks OK to me, it shouldn't giver any errors. I don't quite understand this:
I'm kinda lost on what you're trying to achieve here. Do you have an example of the result you want from the request you posted above?