Python和PostgreSQL-FromText

Python和PostgreSQL-FromText,python,postgresql,Python,Postgresql,我是个Python学习者 我正在尝试将几何体记录插入PostgreSQL 如果我尝试在没有“几何体”列的情况下进行查询,则查询工作正常,并且所有数据都已成功插入 cur.execute("INSERT INTO taxi (userid,carNum) SELECT '"+str(msg['UserID'])+"',"+str(msg['CarNumber'])) 一旦我尝试添加几何体记录,什么都不会发生!执行结束时没有错误,但没有向数据库中插入任何内容 cur.execute("INSERT

我是个Python学习者

我正在尝试将几何体记录插入PostgreSQL

如果我尝试在没有“几何体”列的情况下进行查询,则查询工作正常,并且所有数据都已成功插入

cur.execute("INSERT INTO taxi (userid,carNum) SELECT '"+str(msg['UserID'])+"',"+str(msg['CarNumber']))
一旦我尝试添加几何体记录,什么都不会发生!执行结束时没有错误,但没有向数据库中插入任何内容

cur.execute("INSERT INTO taxi (position,userid,carNum) SELECT GeomFromText('POINT("+str(float(msg['longitude']))+" "+str(float(msg['latitude']))+")',4326),'"+str(msg['UserID'])+"',"+str(msg['CarNumber']))

无法找出此处缺少的内容

您需要将数据提交到数据库

检查psycopg2的文档

遵循这些步骤

>>> import psycopg2

# Connect to an existing database
>>> conn = psycopg2.connect("dbname=test user=postgres")

# Open a cursor to perform database operations
>>> cur = conn.cursor()

# Execute a command: this creates a new table
>>> cur.execute("CREATE TABLE test (id serial PRIMARY KEY, num integer, data varchar);")

# Pass data to fill a query placeholders and let Psycopg perform
# the correct conversion (no more SQL injections!)
>>> cur.execute("INSERT INTO test (num, data) VALUES (%s, %s)",
...      (100, "abc'def"))

# Query the database and obtain data as Python objects
>>> cur.execute("SELECT * FROM test;")
>>> cur.fetchone()
(1, 100, "abc'def")

# Make the changes to the database persistent
>>> conn.commit()

# Close communication with the database
>>> cur.close()
>>> conn.close()