1
candidates = db_session.query(
    Jobs.candidate_id, ## is there a way to eliminate this?
    'Good' ## How do I add this as a column for every person?
    Resumes.resume
).outerjoin(
    (Resumes, Resumes.candidate_id == Jobs.candidate_id),
).outerjoin(
    (Candidate, Candidate.candidate_id == Jobs.candidate_id)

Is there a way I can add Good as the first column to every result?

Additionally, can I eliminate the Jobs category from the Query without breaking the outerjoin?

Update -

can = db_session.query(
    sqlalchemy.sql.expression.literal_column("Good"),
    Jobs.candidate_id

I get this error:

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such column: Good 

I'm using SQLite.

3
  • Adding the string literal: stackoverflow.com/questions/7533146/… Commented May 11, 2019 at 10:24
  • @IljaEverilä still getting an error. I added what I changed Commented May 11, 2019 at 14:17
  • 1
    literal_column() puts the string as is in to the query, so in that case it's up to you to quote it correctly. If you want to produce an SQL literal from a Python value, use literal() instead. Commented May 11, 2019 at 15:58

1 Answer 1

2

You were very close in your update: use literal_column, but make sure to put the value in single quotes.

In your case:

sqlalchemy.sql.expression.literal_column("Good"),

Should be:

sqlalchemy.sql.expression.literal_column("'Good'"),

Your entire query would then look like this:

candidates = db_session.query(
    Jobs.candidate_id, ## is there a way to eliminate this?
    sqlalchemy.sql.expression.literal_column("'Good'").label("optional_column_name"),
    Resumes.resume
).outerjoin(
    (Resumes, Resumes.candidate_id == Jobs.candidate_id),
).outerjoin(
    (Candidate, Candidate.candidate_id == Jobs.candidate_id)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.