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.
-
What version of Postgres are you on?Kuberchaun– Kuberchaun2013-10-24 22:49:28 +00:00Commented Oct 24, 2013 at 22:49
Add a comment
|
1 Answer
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.