Reputation: 361
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.
Upvotes: 1
Views: 599
Reputation: 312
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.
Upvotes: 3