0

I have been trying to migrate my databases from MySql to Postgres but I've encountered a big issue that I can't seem to find how to fix.

I have a row inserted into the table called "users" and that table has Columns such as UserID, Username, etc. as seen here: enter image description here

Now In my C# Code that is accessing the Database and grabbing the data, Im sending this query to the database:

SELECT * FROM users WHERE 'Username'='Eevee';

Which I tried, but that only resulted in me not getting any rows out of that query as shown here: enter image description here

I tried querying it without those quotes around the Column name but that only resulted in me getting the

ERROR:  column "username" does not exist
LINE 1: SELECT * FROM users WHERE Username='Eevee'
                                  ^
HINT:  Perhaps you meant to reference the column "users.Username".

Which one of my friends hinted to happens because Postgres makes everything outside of quotes lowercase, but then we're back to the other issue.

Im new to Postgres and I'm trying to learn this but this is a hard wall that I can't seem to fix myself.

Thanks in advance!

4

1 回答 1

1

最好不要有混合大小写名称的列或表。如果你碰巧有一个,你应该用双引号将标识符名称括起来",而不是单引号,单引号用于字符串文字:

SELECT * FROM users WHERE "Username" = 'Eevee'

PS在第一种情况下,您只是比较了两个字符串,'Username'它们'Eevee'自然不相似。因此,您得到 0 行响应。

于 2020-10-24T19:34:07.707 回答