1

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!

1 Answers1

1

It's best not to have columns or tables with mixed-case names. If you happen to have one, you should enclose the identifier name with double-quotes " instead of single-quotes which are meant for string literals:

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

P.S. In the first case, you just compared two strings, 'Username' and 'Eevee' which are naturally not similar. Therefore, you got 0 rows in response.

Jonathan Jacobson
  • 1,441
  • 11
  • 20
  • Oh my god, i feel so stupid LOL. this worked perfectly, thank you for saving me! – Arkadiusz Brzoza Oct 24 '20 at 19:36
  • 1
    @ArkadiuszBrzoza there's no need to feel stupid, you're new to this. If the system is not yet operational then I would suggest that you rename all tables and columns to lower-case. For clarity, you can separate between words with underscores. – Jonathan Jacobson Oct 24 '20 at 19:38