在创建表P时在psql中使用变量

2024-06-10 11:07:54 发布

您现在位置:Python中文网/ 问答频道 /正文

这是python创建表空间脚本,我需要使用变量跟随位置

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])

当然,PGSQL_HOME将被视为一个字符串,并且不能接受路径值,有没有其他方法可以在脚本中创建表空间?在


Tags: thepathtest脚本homeinputrawtype
1条回答
网友
1楼 · 发布于 2024-06-10 11:07:54

我不知道我是否得到了你,如果你想得到输入变量,你应该这样使用它:

ctbsql = "CREATE TABLESPACE test OWNER tester LOCATION '%s/9.0/data/testspc';"  % (PGSQL_HOME)

相关问题 更多 >