Automatic create new Postgre DB

I would like to know if I can dynamically create a new PostGreeSQL database direct from Xojo.

I’m new in Xojo, and my idea is to create one database by company; like:

Company 1 --> DATABASE1
Company 2 --> DATABASE2

Company n --> DATABASEn

Is this possible?

Not directly, but you can use the Shell to do this using the command line tools that come with PostgreSQL.

But reconsider this. If you are using the same database structure in a central database, you are better off combining all the data into one database and limiting access to each company. Potentially, you can use Row Level Security to make this transparent.

Otherwise, every time you make a change to the db structure, you will have to apply it to every copy of the database.

Actually, you can: Create Database. But, you have to be connected as a superuser, which could have some security implications (hopefully you’re not normally using a superuser for connecting from Xojo - you should be using an appropriately limited user for each database).

But, as Kem points out, you need to consider the cost of structure changes. But, if this is really the direction you need to take, you do get the benefit of optionally basing the new database on a template db that you have created.

Jay, I’m not by my machine to check myself. Are you sure that’s available in PostreSQL?

Yes, I linked to the docs that shows the SQL command. In fact, it states that the command line tool createdb is just a wrapper for this SQL command.

Have a like for linking to documentation!

Ah, I see. Thanks.