will / crystal-pg

a postgres driver for crystal
BSD 3-Clause "New" or "Revised" License
462 stars 77 forks source link

Tables with upcase symbols not readed #261

Closed kostya closed 1 year ago

kostya commented 1 year ago

With downcased tables it works. In ruby it works with any case.

db.query("select id from my_DATA limit 1") do |rs|
  p rs.column_count
  rs.each do
    p rs.read
  end
end

Unhandled exception: relation "my_data" does not exist (PQ::PQError) from lib/pg/src/pq/connection.cr:215:7 in 'handle_error' from lib/pg/src/pq/connection.cr:198:7 in 'handle_async_frames' from lib/pg/src/pq/connection.cr:174:7 in 'read' from lib/pg/src/pq/connection.cr:169:7 in 'read' from lib/pg/src/pq/connection.cr:447:31 in 'expect_frame' from lib/pg/src/pq/connection.cr:446:5 in 'expect_frame' from lib/pg/src/pg/statement.cr:18:5 in 'perform_query' from lib/db/src/db/statement.cr:93:9 in 'perform_query_with_rescue' from lib/db/src/db/statement.cr:80:7 in 'query:args' from lib/db/src/db/pool_statement.cr:29:30 in 'query:args' from lib/db/src/db/query_methods.cr:46:7 in 'query:args' from lib/db/src/db/query_methods.cr:61:7 in '__crystal_main'

kostya commented 1 year ago

ok, after some googling, i found that i need to add quotes. "select id from \"my_DATA\" limit 1"

will commented 1 year ago

Yeah this would be the same as if you were running the query in psql. Most ORMs will auto quote everything to avoid problems, but I don’t think that's appropriate for the driver itself to do.

I tend to keep all table and column names lowercase just to avoid having to quote.

You might also want to use the %() strings to avoid having to do backslashes everywhere. db.query(%q(select id from "my_DATA" limit 1))