Add custom column to 'GraphQL' select query #2624
|
Can I somehow add a column that doesn't exist on the queried table to a 'GraphQL'-style select? Like: await supabase
.from('table')
.select(`
id,
...,
true as exampleBool,
42 as exampleNum
`);
//Result:
table = {
id: 1,
...,
exampleBool: true,
exampleNum: 42
} |
Answered by
steve-chavez
Aug 2, 2021
Replies: 3 comments 2 replies
|
This is not possible, why not just do this in javascript land rather then trying to get it back as part of the results? |
1 reply
|
Another solution is to create a postgres view and query that instead. Not particularly relevant for simple cases, but helpful if you want joins, more complicated queries, or to offload work to the database. |
1 reply
|
Computed columns look fit for this case. Though they usually "compute" a value based on other columns they can also be used for constants. CREATE FUNCTION "exampleNum"(my_table) RETURNS int AS $$
SELECT 42;
$$ LANGUAGE SQL;await supabase
.from('my_table')
.select(`
id,
...,
exampleNum
`);
//Result:
table = {
id: 1,
...,
exampleNum: 42
} |
0 replies
Answer selected by
steve-chavez
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Computed columns look fit for this case. Though they usually "compute" a value based on other columns they can also be used for constants.