Comments (5)
The query
function doesn't do anything special if you just give it a string, it just defers to pandas. I suspect this is a driver issue.
Can you tell me the full results of the following code?
import psycopg2 as pg
import pandas as pd
# connect to your redshift database
con = pg.connect(user="username", password="password", host="host", port=port, dbname="dbname")
result = pd.io.sql.read_sql("TRUNCATE table_name;", con)
print result
from db.py.
Thanks for the reply.
Running the following (with my Redshift credentials of course)
import psycopg2 as pg
import pandas as pd
# connect to your redshift database
con = pg.connect(user="username", password="password", host="host", port=port, dbname="dbname")
#
#
pd.io.sql.read_sql("TRUNCATE table_name;", con)
Obtains:
---------------------------------------------------------------------------
DatabaseError Traceback (most recent call last)
<ipython-input-15-88f7d66aab7b> in <module>()
8 #
9 #
---> 10 pd.io.sql.read_sql("TRUNCATE table_name;", con)
/home/phil/anaconda3/envs/python2/lib/python2.7/site-packages/pandas/io/sql.pyc in read_sql(sql, con, index_col, coerce_float, params, parse_dates, columns)
419 return pandas_sql.read_sql(
420 sql, index_col=index_col, params=params,
--> 421 coerce_float=coerce_float, parse_dates=parse_dates)
422
423 if pandas_sql.has_table(sql):
/home/phil/anaconda3/envs/python2/lib/python2.7/site-packages/pandas/io/sql.pyc in read_sql(self, sql, index_col, coerce_float, params, parse_dates)
1044 parse_dates=None):
1045 args = _convert_params(sql, params)
-> 1046 cursor = self.execute(*args)
1047 columns = [col_desc[0] for col_desc in cursor.description]
1048 data = self._fetchall_as_list(cursor)
/home/phil/anaconda3/envs/python2/lib/python2.7/site-packages/pandas/io/sql.pyc in execute(self, *args, **kwargs)
1039
1040 ex = DatabaseError("Execution failed on sql: %s" % args[0])
-> 1041 raise_with_traceback(ex)
1042
1043 def read_sql(self, sql, index_col=None, coerce_float=True, params=None,
/home/phil/anaconda3/envs/python2/lib/python2.7/site-packages/pandas/io/sql.pyc in execute(self, *args, **kwargs)
1028 cur.execute(*args, **kwargs)
1029 else:
-> 1030 cur.execute(*args)
1031 return cur
1032 except Exception as e:
DatabaseError: Execution failed on sql: TRUNCATE table_name;
from db.py.
I'm not sure if this is helpful but I noted that queries like
db.query("select count(*) from table_name;")
work as expected on my machine
from db.py.
The bug is in pandas (or the driver as @ericchiang as mentioned) and not in db.py
. I don't know if it is specific to redshift but the underlying issue is that the TRUNCATE
and other commands are just that- commands and not queries. I ran into the same issue when trying to set my schema search path. Instead of using the query
method using the cursor directly is the better approach, for example:
db.cur.execute("set search_path to blah;")
from db.py.
OK, thanks. Closing this as it is not a bug in db.py
.
from db.py.
Related Issues (20)
- Is db.py dead?
- question about the template engine pybars HOT 1
- example from twitter apparently doesn't work on Python3 HOT 1
- DB.query_from_file limit doesn't work
- Name conflict between column name and Table property HOT 1
- Connection Issue: AttributeError "Can't set attribute" /DataBase Error "Server closed the connection unexpectedly"
- postgres: AttributeError: can't set attribute. HOT 2
- Generate schema based on regex
- Executing set time_zone queries returns with an error
- 'DB' object has no attribute 'driver' when loading MSSQL profile HOT 1
- db.tables error HOT 1
- Postgres/Psycopg2 DatabaseErrror
- Handlebars partial support
- Ask for SSL over Postgres/RDS
- UnicodeEncodeError with Unicode query parameter
- Silence logging messages
- name 'ColumnSet' is not defined
- print "var", var HOT 1
- MSSQL / _gen_tables_from_col_tuples failed - Missing schema HOT 1
- Documentation enhancement
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from db.py.