title: Truncating all the tables in a schema in PostgreSQL
body: <p>I am trying to truncate all the tables in a schema using PostgreSQL. It is showing this error:</p>
  
  <pre><code>ERROR:  relation "Building" does not exist
  CONTEXT:  SQL statement "TRUNCATE TABLE "Building" CASCADE"
  PL/pgSQL function truncate_schema(character varying) line 15 at EXECUTE statement
  </code></pre>
  
  <p>Here is the function I used:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION truncate_schema(schema IN VARCHAR) RETURNS void AS $$
  DECLARE
      statements CURSOR FOR
          SELECT table_name FROM information_schema.tables
  WHERE table_type = 'BASE TABLE' AND table_schema = schema;
  BEGIN
      FOR stmt IN statements LOOP
          EXECUTE 'TRUNCATE TABLE ' || quote_ident(stmt.table_name) || ' CASCADE';
      END LOOP;
  END;
  $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p>How to do this properly?</p>