Skip to content

SELECT NULL AS #81

@hiFloh

Description

@hiFloh

how do i select null as something?

I have the following Tables in a mariadb.

CREATE TABLE pos (
  id INT,
  ts DATETIME,
  lon DOUBLE,
  lat DOUBLE
);

CREATE TABLE spec (
  id INT,
  ts DATETIME,
  type  enum('sensor1','sensor2')
  content INT
);

Now i want to use the following SQL statement.

SELECT ts, lon, lat, NULL AS leads FROM pos WHERE id = :id
UNION ALL
SELECT ts, NULL, NULL , content FROM spec WHERE id = :id AND type='sensor1'
GROUP BY ts ORDER BY ts;

my current solution compiles, but i would like to use std::optional to check whether a value existed at the specific time

SQLPP_ALIAS_PROVIDER(sensor1);
SQLPP_ALIAS_PROVIDER(timestamp);
(int id){

auto position=select(pos.ts.as(timestamp),pos.lon,pos.lat,sqlpp::value(NULL).as(senor1)).where(pos.id==id);
auto sensor1=select(spec.ts.as(timestamp),sqlpp::value(0.0).as(pos.lon),sqlpp::value(0.0).as(pos.lat),spec.content.as(sensor1).where((spec.id==id)&&spec.type=="sensor1"))
db(position.union_all(sensor1));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions