psycopg

psycopg - Get formatted sql instead of executing

末鹿安然 提交于 2019-11-29 09:12:25
I have a piece of Python code, that interacts with a PostgreSQL database via psycopg. All literature warns against doing sql formatting by oneself, and recommends letting the driver do it. E.g.: cur.execute('select name, age from people where name = %s;', ('ann',) ) The driver then formats the sql string. Let's say I don't want to execute anything, but I just want the fully formatted sql string. Is there any functionality for getting this formatted sql in the psycopg module? you wold use function curs.mogrify(): SQLstring = curs.mogrify('select name, age from people where name = %s;', ('ann',)

brew services

我的梦境 提交于 2019-11-29 00:35:18
mysql brew services start mysql /Users/huoyinghui/workspaces/py2/lib/python2.7/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>. """) 来源: oschina 链接: https://my.oschina.net/tplinuxhyh/blog/3134458

brew services

送分小仙女□ 提交于 2019-11-29 00:20:56
mysql brew services start mysql /Users/huoyinghui/workspaces/py2/lib/python2.7/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>. """) 来源: oschina 链接: https://my.oschina.net/tplinuxhyh/blog/3134458

psycopg - Get formatted sql instead of executing

笑着哭i 提交于 2019-11-28 02:36:12
问题 I have a piece of Python code, that interacts with a PostgreSQL database via psycopg. All literature warns against doing sql formatting by oneself, and recommends letting the driver do it. E.g.: cur.execute('select name, age from people where name = %s;', ('ann',) ) The driver then formats the sql string. Let's say I don't want to execute anything, but I just want the fully formatted sql string. Is there any functionality for getting this formatted sql in the psycopg module? 回答1: you wold use

Psycopg2 Insert Into Table with Placeholders

半世苍凉 提交于 2019-11-27 11:41:48
问题 This might be a rather silly question but what am I doing wrong here? It creates the table but the INSERT INTO doesn't work, I guess I'm doing something wrong with the placeholders? conn = psycopg2.connect("dbname=postgres user=postgres") cur = conn.cursor() escaped_name = "TOUR_2" cur.execute('CREATE TABLE %s(id serial PRIMARY KEY, day date, elapsed_time varchar, net_time varchar, length float, average_speed float, geometry GEOMETRY);' % escaped_name) cur.execute('INSERT INTO %s (day,elapsed

python adds “E” to string

只谈情不闲聊 提交于 2019-11-27 09:04:02
This string: "CREATE USER %s PASSWORD %s", (user, pw) always gets expanded to: CREATE USER E'someuser' PASSWORD E'somepassword' Can anyone tell me why? Edit: The expanded string above is the string my database gives me back in the error message. I'm using psycopg2 to access my postgres database. The real code looks like this: conn=psycopg2.connect(user=adminuser, password=adminpass, host=host) cur = conn.cursor() #user and pw are simple standard python strings the function gets as parameter cur.execute("CREATE USER %s PASSWORD %s", (user, pw)) conn.commit() Yann Vernier Not only the E but the

python adds “E” to string

感情迁移 提交于 2019-11-26 17:48:43
问题 This string: "CREATE USER %s PASSWORD %s", (user, pw) always gets expanded to: CREATE USER E'someuser' PASSWORD E'somepassword' Can anyone tell me why? Edit: The expanded string above is the string my database gives me back in the error message. I'm using psycopg2 to access my postgres database. The real code looks like this: conn=psycopg2.connect(user=adminuser, password=adminpass, host=host) cur = conn.cursor() #user and pw are simple standard python strings the function gets as parameter