Answer the question
In order to leave comments, you need to log in
How to set the table name using a variable?
Good day to all. New to DB. I am writing a script that should create a table at a given time. I need its name to be given to a variable.
import psycopg2
a="abc"
cur = con.cursor()
cur.execute('''CREATE TABLE xxx
(VM_UUID CHAR(200) PRIMARY KEY NOT NULL,
VM_NAME CHAR(200),
CPU INT NOT NULL,
MEMORY DECIMAL NOT NULL);''')
Answer the question
In order to leave comments, you need to log in
I understand you are a beginner in python
like this:
a="abc"
cur = con.cursor()
cur.execute("""CREATE TABLE %s
(VM_UUID CHAR(200) PRIMARY KEY NOT NULL,
VM_NAME CHAR(200),
CPU INT NOT NULL,
MEMORY DECIMAL NOT NULL)""" % a)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question