Replies: 3 comments
-
CREATE TABLE "2nd_table" ( "2nd_id" int, "2nd_name" text);
SELECT * FROM "2nd_table";
┌────────┬──────────┐
│ 2nd_id │ 2nd_name │
├────────┼──────────┤
└────────┴──────────┘ So the error lies within |
Beta Was this translation helpful? Give feedback.
-
Thanks for your reply. CREATE TABLE public."2nd_table" (...);
ALTER TABLE ONLY public."2nd_table"
ADD CONSTRAINT "second_table_fkey_fkey" FOREIGN KEY (fkey) REFERENCES public.first_table(id); As mentioned above, the table is correctly created, but the Foreign key isn't. I tried your suggestion, using I've changed the names of my tables to avoid this issue, but it seems a little worrying to me that this constraint is not created, and there seems to be no warning or anything (psql does not say anything). Is there a way I can see the server logs for my db? If so, I'll dig a little bit further to understand where the issue is. |
Beta Was this translation helpful? Give feedback.
-
Hey @laurentS - I am going to convert this to a Discussion as it seems to be more of an issue with pgdump/psql than anything we can fix ourselves. I'm sure others could find this and comment or share tips |
Beta Was this translation helpful? Give feedback.
-
Bug report
Describe the bug
I got stuck trying to figure out why my foreign keys were not rebuilt with a loop of
pg_dump
+psql
. It turns out that one of my table had what seems to be an invalid name, based on the postgresql docs.To Reproduce
first_table
with just the default primary key (the names matter)2nd_table
with the default primary key2nd_table
namedfkey
and make it referenceid
infirst_table
pg_dump -h db.xxxx.supabase.co -U postgres -W --schema-only --schema=public > db.sql
to export the schemapsql -h db.xxxx.supabase.co -U postgres < db.sql
to restore the schema2nd_table
/fkey
and notice that the foreign key has not been restoredIf the table is named
second_table
instead of2nd_table
then everything works fine. You can try this out by doing something likes/2nd_/second_/g
in the dumped file.Expected behavior
Based on the postgresql docs linked above,
2nd_table
does not seem to be a valid table identifier. From4.1.1
in the docs:This tells me that a digit in the first position is not valid. The weird thing is that there is no error nor warning, but things don't work as expected: I expect that the foreign key should be recreated, or postgresql should tell me there is an error, not just silently ignore it.
I see 2 options:
I'm not entirely sure what the solution is here, but my guess would be that supabase should check the identifier and not let me use it in this case.
Beta Was this translation helpful? Give feedback.
All reactions