0

I have a website (Laravel & AngularJS) which used MySQL. Now i'm trying to change to Postgres, the database is created and accessible (with all the columns in lowercase which i can't change because there's another application sharing the database). The problem is Laravel's Illuminate is creating the db queries with quotes around the columns' keys like this:

DB::table('generalsettings')->where('settingsKey', '=', 'LicenseSerial');

this creates: SELECT * FROM "generalsettings" WHERE "settingsKey"='LicenseSerial'

Which doesn't work due to the columns' key lowercase. Is there anyway to configure Illuminate's DB to not append quotes to columns keys?

1
  • If I'm reading this right, the problem is that the columns name is lowercase while the name you're sending it is not? Commented Mar 10, 2017 at 14:53

1 Answer 1

0

No, there is no config value or anything to control this at the application level. Your best bet is to just know that your column names are case sensitive, and make sure to write your queries correctly.

There are two other options, but they're not pretty.

First, Laravel will not wrap expressions, so the following would work:

DB::table('generalsettings')->where(DB::raw('settingsKey'), '=', 'LicenseSerial');

This, of course, means you'd have to wrap every column name you specify with a call to DB::raw().

The second option would be extending and overriding files in the query builder to stop escaping the columns. This would be a lot of work and very error prone. I won't go into the details, but you'd end up having to override the PostgresGrammar, Grammar, and PostgresConnection, at a minimum, and then wire them all together in a service provider.

Sign up to request clarification or add additional context in comments.

1 Comment

i'm going to lowercase all the columns names in my code. More work but less risk, i think. Thank you for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.