title: Dockerized postgres: How to define a procedure in a specific database?
body: <p>I have the following setup for my postgres docker container:</p>
  <pre><code>mydir &gt; tree
  .
  ├── Dockerfile
  ├── proc_createInstallerUser.sql
  ├── docker-entrypoint-initdb.d
  └── init.sql
  </code></pre>
  <pre><code>mydir &gt; cat Dockerfile
  FROM postgres
  COPY init.sql /docker-entrypoint-initdb.d/
  COPY proc_createInstallerUser.sql /docker-entrypoint-initdb.d/
  </code></pre>
  <pre><code>mydir &gt; cat init.sql
  CREATE USER appUser WITH LOGIN PASSWORD 'appUser';
  CREATE DATABASE testdb OWNER appUser;
  GRANT ALL PRIVILEGES ON DATABASE testdb TO appUser;
  </code></pre>
  <pre><code>mydir &gt; cat proc_createInstallerUser.sql
  create or replace procedure public.createNewInstallerUser(newUserName varchar, newPassword varchar)
      language plpgsql
  as $procedure$
      begin
          raise notice 'Create newInstallerUser() called with arguments % %', newUserName, newPassword;
      end;
  $procedure$;
  ;
  </code></pre>
  <p>Docker faithfully executes my init.sql and proc_createInstallerUser.sql, but my stored procedure is defined in a database named &quot;root&quot;. I'd like for it to be placed in my &quot;testdb&quot; database that I create in my init.sql. I tried inserting a &quot;connect to testdb&quot; statement as the first line of my stored procedure, but that's throwing a syntax error. How would I go about defining the procedure in the correct database instead of it defaulting to root?</p>