I’m working on a bit of python code to run a query against a redshift (postgres) SQL database, and I’m running into an issue where I can’t strip off the surrounding single quotes from a variable I’m passing to the query. I’m trying to drop a number of tables from a list. This is the basics of my code:

1

2

3

4

5

6

7def func(table_list):

drop_query = 'drop table if exists %s' #loaded from file

table_name = table_list[0] #table_name = 'my_db.my_table'

con=psycopg2.connect(dbname=DB, host=HOST, port=PORT, user=USER, password=PASS)

cur=con.cursor()

cur.execute(drop_query, (table_name, )) #this line is giving me trouble

#cleanup statements for the connection

table_list =

1['my_db.my_table']

when func() gets called, I am given the following error:

1

2

3syntax error at or near "'my_db.my_table'"

LINE 1: drop table if exists 'my_db.my_table...

^

Is there a way I can remove the surrounding single quotes from my list item?

for the time being, I’ve done it (what think is) the wrong way and used string concatenation, but know this is basically begging for SQL-injection.

python去掉列表中的单引号_Python:如何从列表项中删除单引号(Python: How to remove single quotes from list item)...相关推荐

  1. python代码什么时候用单引号_Python 中的单引号和双引号有什么区别?

    在Python当中可以使用单引号,也可以使用双引号,那两者有什么区别吗? 简单来说,在Python中使用单引号或双引号是没有区别的,都可以用来表示一个字符串.但是这两种通用的表达方式,除了可以简化程序 ...

  2. python中3个单引号_Python中单引号,双引号,3个单引号及3个双引号的区别

    单引号和双引号 在Python中我们都知道单引号和双引号都可以用来表示一个字符串,比如 str1 = 'python'str2= "python" str1和str2是没有任何区别 ...

  3. Python中的单引号,双引号,三重引号的区别

    经常有人问Python中的单引号,双引号,三重引号的区别,其实上还是有区别的. 单引号和双引号基本上没什么区别,区别只在于下面这种情况. >>> S1 = 'I do like &q ...

  4. python方括号里面单引号_Python中单引号,双引号,三个单引号,外双单引号内双引号,外双引号内单引号的区别...

    Python 中一对单引号和一对双引号都可表示一个字符串: 1 Str1 = 'python' 2 Str2 = "python" 思考? 如何表示字符串: I ' am a py ...

  5. sql插入语句中value中含有单引号

    2019独角兽企业重金招聘Python工程师标准>>> 如果插入数据库的字符串中还有单引号,需要转义处理,如插入"It's a tree.",SQL语句如下: I ...

  6. mysql sql语句 引号_关于sql:何时在MySQL中使用单引号,双引号和反引号

    我正在尝试学习编写查询的最佳方法. 我也理解保持一致的重要性. 到现在为止,我已经随机使用单引号,双引号和反引号而没有任何实际想法. 例: $query = 'INSERT INTO table (i ...

  7. sqlserver 字符串中添加单引号_Python3 教程-- 7、字符串

    Python 字符串 除了数字,Python也能操作字符串.字符串有几种表达方式,可以使用单引号或双引号括起来: >>> 'spam eggs''spam eggs'>> ...

  8. oracle update单引号,Oracle学习笔记:update的字段中包括单引号

    平时update的时候直接更改字段内的值,例如: update table_temp set name = 'Hider' where id = 100; 但更新后的值中包括单引号,则不能按以上方式进 ...

  9. Latex中的单引号,双引号如何输入?

    Latex中的单引号,双引号如何输入? 左单引号:` 左双引号:`` 右单引号:' 右双引号:''

最新文章

  1. 树莓派3b+目标检测: tflite 运行 mobilenet ssd
  2. 一次性讲清 Spring 常用注解 @Bean 、 @Component 、@Autowire、@Resource 的区别, 你知道吗?
  3. 如何生成java_如何生成JavaAPI doc
  4. python(numpy,pandas1)——numpy(ndim,shape,size,zero, empty, arange, linspace)
  5. 52. N-Queens II
  6. linux下添加服务,Linux下添加服务
  7. c# mysql数据库查询语句_C# mysql 查询
  8. 使用putty连接本地VirtualBox上的centos7 linux主机
  9. FFmpeg源代码简单分析:结构体成员管理系统-AVOption
  10. 《青春》—塞缪尔·厄尔曼
  11. 【电力负荷预测】基于matlab粒子群算法优化支持向量机预测电力负荷【含Matlab源码 1225期】
  12. matlab 简介_MATLAB简介
  13. Exadata通过ILOM远程MOUNT ISO实现刷机Reimage
  14. android 安装在笔记本,笔记本安装安卓系统图解_笔记本电脑如何安装安卓系统-win7之家...
  15. 计算机基础知识大全之硬件篇
  16. Mybatis Plus 看这篇就够了,通俗易懂,一发入魂
  17. 第一行代码-第二版(郭霖著)笔记(初识Android)
  18. 解决微信浏览器video全屏的问题及黑边问题
  19. Gmail,google.com等谷歌英文网站被封解决办法
  20. 談話的力量:談話技巧助你成功

热门文章

  1. 1034. 有理数四则运算(20)
  2. 没有android:padding属性,android自定义无上下padding的textview
  3. 【Linux进程、线程、任务调度】四多核下负载均衡 中断负载均衡,RPS软中断负载均衡 cgroups与CPU资源分群分配 Linux为什么不是硬实时 preempt-rt对Linux实时性的改造
  4. RabbitMQ(1) - win+rabbitMQ
  5. Linux中常用命令(文件与目录)
  6. CSS-posiziton
  7. Delphi 对象的创建(create)与释放(free/destory)
  8. [Buzz.Today]2013.03.14
  9. 基于web的工作流设计器(多比图形控件)
  10. Java学习笔记9-2——JavaWeb