Search code examples
mysqlknex.jsuppercase

How to select a column in knex getting the result in UPPERCASE?


I am trying to select from a table the column name, but would like to get it all caps, using UPPER. I would like to to it without using Knex raw SQL, but it doesn't work.

That's what I am trying to do:

        const usersJornadasComites = await Database.table('tb_usuario_jornada')
        .where('tb_usuario_jornada.jornada_id', lastJornad.id)
        .where('tb_usuario_jornada.comite_id', params.id)
        .where('tb_usuario_jornada.ativo', 1)
        .select(
            'tb_usuario.id',
            'UPPER(tb_usuario.nome)',
            'tb_usuario.email',
            'tb_usuario.celular',
            'tb_usuario.dt_nascimento',
            'tb_usuario_jornada.criado_em',
            'tb_usuario.id',
            'tb_usuario_jornada.usuario_id'
        )
        .leftJoin(
            'tb_usuario',
            'tb_usuario_jornada.usuario_id',
            'tb_usuario.id'
        )

It gives me an error saying that UPPER(tb_usuario.nome) is not a valid column name. Any ideas?

Many thanks,

Gines


Solution

  • just to inform if somebody else has the same issue. The solution I used was to instead of using ORM syntax, I used the knex.raw select and it worked properly.