Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select uppercase table name on postgreSQL is not working [duplicate]

I'm using psycopg2 on windows7 and python3.4.4.

I'd like to get data from tables of uppercase name, but I couldn't figure it out. Can anyone help me?

Always retuturn like this relation "table" does not exist I want to make "table" uppercase.

here's my code import psycopg2

class KindOfCoupons:

   def get_coupons(self, cur, names):
       coupons = {}
       for name in names:
           coupons[name] = cur.execute("SELECT * FROM \"" + name + "\" ;")
       return coupons

   def connect_redshift(self):
       conn = psycopg2.connect("dbname=dbname host=host user=user password=password port=000")
       return conn.cursor()

   def get_coupon_used_type(self):
       cur = self.connect_redshift()
       names = ["TABLE", "TABLE_B", "TABLE_C"]
       coupons = self.get_coupons(cur, names)
       coupons[names[0]][0]
like image 996
Masaru Iwasa Avatar asked Oct 26 '25 16:10

Masaru Iwasa


1 Answers

PostgresSQL column and table names are case insensitive, unless you surround them with quotes (like you do, "SELECT * FROM \"" + name + "\" ;").

See this answer: https://stackoverflow.com/a/21798517/1453822

like image 88
DeepSpace Avatar answered Oct 29 '25 05:10

DeepSpace



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!