GithubHelp home page GithubHelp logo

Comments (3)

matthijs avatar matthijs commented on August 11, 2024

For postgresql you need to specifiy all columns in the group by statement (except for the aggregate), so it should look like this:

auto records = _connection(
    select(
        reports.id, 
        reports.aoi, 
        reports.toi, 
        reports.roi, 
        reports.story, 
        reports.created, 
        reports.properties,
        reports.author,
        users.firstName, 
        users.lastName,
        count(places.id)
    ).from(
        reports.join(users).on(reports.author == users.id).left_outer_join(places).on(reports.id == places.report)
    ).group_by(reports.id, reports.aoi, reports.toi, reports.roi, reports.story, reports.created, reports.properties, reports.author, users.firstName, users.Lastname)
     .limit(limit).offset(offset).order_by(reports.id.asc()).unconditionally()
);

from sqlpp11-connector-postgresql.

neel avatar neel commented on August 11, 2024

But in PgAdmin SQL query works only with group by reports.id.

I tried including all the fields. the reports.properties is of type json but in sqlpp11 it is mapped as text

It gave me exceptions

ERROR:  could not identify an equality operator for type json
LINE 1: ...rts.toi,reports.roi,reports.story,reports.created,reports.pr...
                                                             ^
unhandled exception ERROR:  could not identify an equality operator for type json
LINE 1: ...rts.toi,reports.roi,reports.story,reports.created,reports.pr...
                                                             ^

from sqlpp11-connector-postgresql.

rbock avatar rbock commented on August 11, 2024

Interesting. I thought that @matthijs is right, but maybe there are rules for joins that allow this? Iยดd be thankful if you could dig up the rules that allow to use group by reports.id only.

However, the rules for select in the library are as stated.

Since you apparently cannot group by the JSON field, I see two options:

  1. Use verbatim. That is a bit hacky, but probably the fastest way.
  2. Restructure your query to join with a select. Something like this (taken from test/Select.cpp):
  auto rowCount = select(t.alpha, count(t.alpha)).from(t).unconditionally().group_by(t.alpha).as(sqlpp::alias::a);
  db(select(f.omega, rowCount.count)
         .from(f.join(rowCount).on(f.omega == rowCount.alpha))
         .unconditionally()
         .order_by(rowCount.count.asc()));

from sqlpp11-connector-postgresql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.