Since you can't have nested schemas I am assuming you want to take the public schema in db A and put it into a named schema in db B.
Here's the simple way to do this (it may require some effort regarding search_path
so that everything is found correctly, particularly regarding functions, but see notes below.
Dump your db from DB A. Restore it into db B
Run the following command on db B:
ALTER SCHEMA public RENAME TO foobar;
You can then alter some users to search for relations and functions in foobar first:
ALTER USER myuser SET search_path=foobar,public;
If you have functions you can:
ALTER FUNCTION foo(bar int) SET search_path=foobar;
I think that covers the basics.
Now if you can't be sure that the public schema is in use, you may want to consult pg_class and pg_namespace to try to determine which schema is involved. You could do this by checking the namespaces of specific tables and try to make sure only one schema is involved. If the same table name occurs in multiple schemas and is the one you are using to detect, then you will need to manually interfere.