Creating Supabase Table dynamically
Unanswered
Giant panda posted this in #help-forum
Giant pandaOP
I want to create a new table when the user sign up, I couldn't find anything that is related to creating new table at the backend in supabase docs, can any help me how can I do that?
15 Replies
Band-tailed Pigeon
@Giant panda can you give us more detail what are you trying to do
Giant pandaOP
I want to create a new table when the user sign up, I couldn't find anything that is related to creating new table at the backend in supabase docs.
I'm building app like chatgpt but which will be own data trained( It could be pdf or txt ), so I build website with nextjs + prisma, which does have sign up and my plan is every user have their table that they can upload the pdf or txt and talk with that
and the pdf will be sliced in to chucks
because it is vector database
so the user could have multiple rows
and it will be so diffcult if all users push data to the same table
and the pdf will be sliced in to chucks
because it is vector database
so the user could have multiple rows
and it will be so diffcult if all users push data to the same table
Normally you can run raw SQL
Prisma doesn't have a create table function, you have to write SQL statement directly.
I'm not familiar with vector databases, but I don't think that's a good way of implementing it since it is not the purpose of creating tables.
CREATE TABLE XXX to create a new table. Prisma doesn't have a create table function, you have to write SQL statement directly.
I'm not familiar with vector databases, but I don't think that's a good way of implementing it since it is not the purpose of creating tables.
Giant pandaOP
@fuma I have tried raw query and also use supabase dashboard to trigger a create function when user signup but not supporting the create
getting this error: Failed to create function: failed to create pg.functions: syntax error at or near "CREATE"
How do you create table (the raw query)?
Giant pandaOP
CREATE OR REPLACE FUNCTION public.create_user_table(user_id uuid)
RETURNS void
LANGUAGE plpgsql
AS $$
BEGIN
EXECUTE '
CREATE TABLE IF NOT EXISTS public.user_' || user_id || ' (
id bigserial,
content text null,
metadata jsonb null,
embedding public.vector null,
-- Define other columns as needed
constraint user_' || user_id || '_pkey primary key (id)
)';
END;
$$;This is a function instead of a statement, in Prisma, you can use
to run raw SQL queries
await prisma.$queryRaw`CREATE TABLE`to run raw SQL queries
Then you can try something like:
CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3));Giant pandaOP
@fuma btw is it the correct approach right? to create a table for every user
I don't know, in traditional relational databases, it's unappreciated. However, it might be different in vector databases
Giant pandaOP
@fuma I'm using supabase
@fuma But I don't if this approach is the correct one or not, because I want the searching to be fast as much as possible.....
Giant pandaOP
??