How do I create a table in postgres that's associated with a specific database?

Obviously from the command line one can do

Create table tablename ();

But how do I make sure that the table is associated with the correct database?

CREATE table dbname.tablename();

is giving me the error:

ERROR:  schema "dbname" does not exist

I believe you need to connect to the appropriate database first, before issuing the create table command. From my understanding, it is not possible to specify a database name from within the create table command.

@Dani,

Thanks! That makes sense, I'll give it a shot.

It worked!

I am building an application and so I decided to create an installation script. It turns out that the installation script must first connect to the database as the postgres user in order to create the databases. What got this working was to fully disconnect and then using both new connection handles and cursor to reconnect as the application account to create the tables inside of the newly minted databases. At this point it's running.

Glad you were able to get it working. I'll mark this question as solved.

Sorry that my initial post was so sparse, I was messaging you from my phone so I wasn't able to be as elaborate as I would have wanted.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.