I have to create database by passing name of the database as parameter in stored procedure in postgressql.
Does postgresql support creating statement in stored procedure
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Jan 21, 2022, 6:29 AM EST
Suraj DubeyRank #2,182 · 647 reputationPosted Jan 22, 2022, 12:52 AM EST
PERFORM replication.dblink_connect('myconn','host=127.0.0.1 port=5432 dbname=mydb user=username password=secret');PERFORM replication.dblink_exec('myconn', 'CREATE DATABASE "DBFROMUSER'||id||'" TEMPLATE "TEMPL'||type||'";',false);PERFORM replication.dblink_disconnect('myconn');Gajendra JangidRank #157 · 14.9K reputationPosted Mar 12, 2022, 5:08 AM EST
Until PostgreSQL version 11, both stored procedures and user-defined functions were created with the CREATE FUNCTION statement. However, beginning with PostgreSQL version 11, procedures can be created using the CREATE PROCEDURE statement.