1

I need to create 1001 tables, table names should be 0-1000 and each table has two double value columns called A and B. How do I create this many tables without executing 1001 CREATE TABLE queries manually? I am using Postgresql on linux.

1
  • What version of Postgres are you on? Commented Oct 24, 2013 at 22:49

1 Answer 1

3

I am sure there is a best way to do this, but you could generate the statements in shell script and then just load the sql.

Something like

#!/bin/sh
NAME="name"
COLUMNA="ca"
COLUMNB="cb"

for i in `seq 0 1000`;
  do
    echo "CREATE TABLE $NAME$i ($COLUMNA varchar(200), $COLUMNB varchar(200));"
  done

Then you just execute sh script.sh > creation.sql and load it with Postgres.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.