i have this basic sql file:
CREATE TABLE `app_users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(200) DEFAULT NULL,
`password` varchar(200) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
and want to execute it via python:
connect_str = "dbname='dbname' user='user' host='192.168.1.101' password='password'"
conn = psycopg2.connect(connect_str)
cursor = conn.cursor()
fd = open('file.sql', 'r')
sqlFile = fd.read()
fd.close()
sqlCommands = sqlFile.split(';')
for command in sqlCommands:
print(command)
if command.strip() != '':
cursor.execute(command)
When i execute this via "python3 app.py", it connects, but i just get:
psycopg2.ProgrammingError: syntax error at or near "`"
LINE 1: CREATE TABLE `app_users` (
But i have no idea why.. anybody could help me with this issue?
thanks and greetings
asked Aug 21, 2017 at 21:35
Creative crypter
1,5268 gold badges34 silver badges71 bronze badges
1 Answer 1
Use the proper Postgresql syntax:
CREATE TABLE app_users (
id serial,
email varchar(200),
password varchar(200),
primary key (id)
)
answered Aug 22, 2017 at 13:02
Clodoaldo Neto
127k30 gold badges251 silver badges274 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Explore related questions
See similar questions with these tags.
default
create tablescript to the PostgreSQL"