When querying an empty table, you get an empty array. There is no way to access column names. In a normal table, you can access the keys of the first row object.
To Reproduce
const result = await supabase.from("an_empty_table").select("*");
result.data and result.error work normally but produce no information about columns
Why? Because I want to show an empty table view with the columns printed out as a loading state before a user adds a row.
E.g., in my case, they are adding a "person" to a "people" table and when people.length == 0 I still want to show the fields as
table headers so visually get an impression of the table, without it directly into the code, and I'm not using the typescript client with generated types, etc., in any case it's a reused component that needs to do so regardless of the model being passed to it.
I noticed you all added this to the Studio codebase a couple years ago:
Hey @zachblume, this is outside the scope of the client library - the response from the query to the REST server doesn't include column information. For this you'd need to query the database directly via SQL (e.g. from information_schema.columns), or you can use the OpenAPI response from the REST server which you can get from:
curl '<your API URL>/rest/v1/' -H 'apikey: <your API key>'
Thanks for the pointer the that endpoint, didn’t realize there was a programmatic one. Should wrap it in a handler for the clients and document it is my $.02
In the end I wrote an RPC to query info schema as you said, but this is better
It would be useful to implement a method in supabase-js to query the /rest/v1/ endpoint without having to extract the API key and bearer token and manually make the fetch call, especially when your app uses custom roles in PostgreSQL.
In such cases, you can provide information to your frontend to generate menus in a dashboard based on tables and views visibility, which varies based on user privileges with PostgREST."
Bug report
Describe the bug
When querying an empty table, you get an empty array. There is no way to access column names. In a normal table, you can access the keys of the first row object.
To Reproduce
result.data and result.error work normally but produce no information about columns
Expected behavior
Perhaps behind a flag, like count?
System information
Additional context
Why? Because I want to show an empty table view with the columns printed out as a loading state before a user adds a row.
E.g., in my case, they are adding a "person" to a "people" table and when people.length == 0 I still want to show the fields as
I noticed you all added this to the Studio codebase a couple years ago:
https://github.com/supabase/supabase/issues/94
Can I work on this @zachblume ?
Hey @zachblume, this is outside the scope of the client library - the response from the query to the REST server doesn't include column information. For this you'd need to query the database directly via SQL (e.g. from information_schema.columns), or you can use the OpenAPI response from the REST server which you can get from:
Thanks for the pointer the that endpoint, didn’t realize there was a programmatic one. Should wrap it in a handler for the clients and document it is my $.02
In the end I wrote an RPC to query info schema as you said, but this is better
It would be useful to implement a method in supabase-js to query the /rest/v1/ endpoint without having to extract the API key and bearer token and manually make the fetch call, especially when your app uses custom roles in PostgreSQL. In such cases, you can provide information to your frontend to generate menus in a dashboard based on tables and views visibility, which varies based on user privileges with PostgREST."