0

Here is the python create tablespace script, I need to use variable following LOCATION,

PGSQL_HOME = raw_input('Type the tablespace location path :>')

ctbsql = "CREATE TABLESPACE test OWNER tester LOCATION 'PGSQL_HOME/9.0/data/testspc';"
subprocess.Popen(['psql', '-U', 'postgres', '-c', ctbsql])

Of course, PGSQL_HOME will treat as a string, and can't take the path value, are there some other methods that I can take to create tablespace in script?

freddy
  • 159
  • 1
  • 4
  • 23
ourfirst
  • 1
  • 2
  • You should probably go through the [strings section](http://docs.python.org/2/tutorial/introduction.html#strings) of the Python tutorial to learn how to concatenate strings. Further, it may be worthwhile to learn to use a database library, like psycopg2, instead of shelling out to psql. – Shane Dec 19 '13 at 03:46

1 Answers1

0

I don't know whether I got you or not, if you want to get the input variable, you should uses it like this:

ctbsql = "CREATE TABLESPACE test OWNER tester LOCATION '%s/9.0/data/testspc';"  % (PGSQL_HOME)
Kane Blueriver
  • 4,170
  • 4
  • 29
  • 48