Utilizzo delle espressioni primarie in SQL
Se si desidera seguire gli esempi, vedere Dati di esempio per eseguire query per visualizzare dati di esempio e imparare a utilizzare OCI Console per creare le tabelle di esempio e caricare i dati utilizzando i file JSON.
Argomenti correlati
Espressioni parentesi
Le espressioni padre vengono utilizzate principalmente per modificare la precedenza predefinita tra gli operatori. Sono anche utilizzati come aiuto sintattico per mescolare le espressioni in modi che altrimenti causerebbero ambiguità sintattiche.
SELECT fullName, bag.bagInfo.tagNum,
bag.bagInfo.routing,
bag.bagInfo[].flightLegs[].fltRouteDest
FROM BaggageInfo bag
WHERE bag.bagInfo.flightLegs[].fltRouteSrc=any "JFK" AND
(bag.bagInfo[].flightLegs[].fltRouteDest=any "MAD" OR
bag.bagInfo[].flightLegs[].fltRouteDest=any "VIE" )
Spiegazione: si desidera recuperare il nome completo, il numero di cartellino e i dettagli di instradamento dei passeggeri. La prima condizione del filtro è che il punto di imbarco/transito sia JFK. Una volta soddisfatta, la seconda condizione del filtro è che la destinazione sia MAD o VIE. Utilizzare una condizione OR per filtrare il valore di destinazione.
{"fullName":"Dierdre Amador","tagNum":"17657806240229","routing":"JFK/MAD","fltRouteDest":"MAD"}
{"fullName":"Rosalia Triplett","tagNum":"17657806215913","routing":"JFK/IST/VIE","fltRouteDest":["IST","VIE"]}
{"fullName":"Kendal Biddle","tagNum":"17657806296887","routing":"JFK/IST/VIE","fltRouteDest":["IST","VIE"]}
Espressioni CASE
L'espressione CASE cercata è simile alle affermazioni if-then-else dei linguaggi di programmazione tradizionali. Si compone di un certo numero di coppie WHEN-THEN, seguito da una clausola ELSE opzionale alla fine. Ogni espressione WHEN è una condizione, cioè deve restituire BOOLEAN. Le espressioni THEN e ELSE possono restituire qualsiasi sequenza di elementi. L'espressione CASE viene valutata valutando innanzitutto le espressioni WHEN dall'alto verso il basso fino alla prima che restituisce true. Se l'espressione i-th WHEN restituisce true, viene valutata l'espressione i-th THEN e il relativo risultato è il risultato dell'intera espressione CASE. Se nessuna espressione WHEN restituisce true, se esiste un ELSE, la relativa espressione viene valutata e il risultato è il risultato dell'intera espressione CASE. In caso contrario, il risultato dell'espressione CASE è la sequenza vuota.
SELECT
fullName,
CASE
WHEN NOT exists bag.bagInfo.flightLegs[0]
THEN "you have no bag info"
WHEN NOT exists bag.bagInfo.flightLegs[1]
THEN "you have one hop"
WHEN NOT exists bag.bagInfo.flightLegs[2]
THEN "you have two hops."
ELSE "you have three hops."
END AS NUMBER_HOPS
FROM BaggageInfo bag WHERE ticketNo=1762340683564
Spiegazione: si desidera determinare il numero di transiti disponibili per il passeggero bagInfo
utilizzando un'istruzione CASE. Se l'array flightLegs
non contiene elementi, il passeggero non dispone di dati relativi al bag. Quando l'array flightLegs
ha un solo elemento, esiste un solo punto di transito. Analogamente, se l'array flightLegs
contiene due elementi, esistono due hop. Altrimenti ci sono tre punti di transito. Qui si suppone che una borsa può avere al massimo tre punti di transito / luppolo.
{"fullName":"Mary Watson","NUMBER_HOPS":"you have two hops."}
tagNum
dei passeggeri se il valore esistente non è una stringa.SELECT bag.bagInfo[].tagNum,
CASE
WHEN bag.bagInfo[0].tagNum is of type (NUMBER)
THEN "Tagnumber is not a STRING. Update the data"
ELSE "Tagnumber has correct datatype"
END AS tag_NUM_TYPE
FROM BaggageInfo bag
Spiegazione: il tagNum
dei passeggeri nello schema bagInfo
è un tipo di dati STRING. Ma l'applicazione potrebbe assumere un valore NUMBER come valore di tagNum
per errore. La query utilizza l'operatore "è di tipo" per acquisirla e richiede al sistema di aggiornare tagNum
se il valore esistente non è una stringa.
{"tagNum":"17657806240001","tag_NUM_TYPE":"Tagnumber has correct datatype"}
{"tagNum":"17657806224224","tag_NUM_TYPE":"Tagnumber has correct datatype"}
{"tagNum":17657806243578,"tag_NUM_TYPE":"Tagnumber is not a STRING. Update the data"}
{"tagNum":"1765780623244","tag_NUM_TYPE":"Tagnumber has correct datatype"}
Espressione Cast
L'espressione cast crea, se possibile, nuovi elementi di un determinato tipo di destinazione dagli elementi della relativa sequenza di input. Ad esempio, è possibile convertire una STRING in TIMESTAMP(0) utilizzando l'espressione CAST.
- Se il tipo di elemento di input è uguale al tipo di elemento di destinazione, il cast è no-op: viene restituito l'elemento di input stesso.
- Se il tipo di destinazione è un carattere jolly diverso da JSON e il tipo di elemento di input è un sottotipo del tipo di carattere jolly, il cast è no-op.
- Se il tipo di destinazione è JSON, viene generato un errore se l'elemento di input è di tipo atomico non json.
- Se il tipo di destinazione è un tipo di array, viene generato un errore se l'elemento di input non è un array.
- Se il tipo di destinazione è stringa, l'elemento di input può essere di qualsiasi tipo. Ciò significa che ogni elemento può essere proiettato in una stringa. Per gli indicatori orari, il relativo valore stringa è in UTC e ha il formato
uuuu-MM-dd['T'HH:mm:ss]
. - Se il tipo di destinazione è un tipo atomico diverso da stringa, anche l'elemento di input deve essere atomico.
-
- È possibile eseguire il cast di numeri interi e lunghi in indicatori orari. Il valore di input viene interpretato come il numero di millisecondi dal 1° gennaio 1970, 00:00:00 GMT.
- Gli elementi stringa possono essere castable per tutti gli altri tipi atomici. La riuscita o meno del cast dipende dal fatto che il valore stringa effettivo possa essere analizzato in un valore appartenente al dominio del tipo di destinazione.
- Gli elementi indicatore orario possono essere convertiti in cast per tutti i tipi di indicatore orario. Se il tipo di destinazione ha una precisione minore rispetto all'elemento di input, l'indicatore orario risultante è quello più vicino all'indicatore orario di input nella precisione di destinazione.
-
- Per convertire una STRING in TIMESTAMP, se l'input contiene valori STRING in formato ISO-8601, verrà convertito automaticamente dal runtime SQL in tipo di dati TIMESTAMP.
Nota
ISO8601 descrive un modo accettato a livello internazionale per rappresentare date, orari e durate.Syntax: Date with time: YYYY-MM-DDThh:mm:ss[.s[s[s[s[s[s]]]]][Z|(+|-)hh:mm]
dove- YYYY specifica l'anno come quattro cifre decimali
- MM specifica il mese, come due cifre decimali, da 00 a 12
- DD specifica il giorno, come due cifre decimali, da 00 a 31
- hh specifica l'ora, come due cifre decimali, da 00 a 23
- mm specifica i minuti, come due cifre decimali, da 00 a 59
- ss[.s[s[s[s[s]]] specifica i secondi, come due cifre decimali, da 00 a 59, facoltativamente seguiti da una virgola decimale e da 1 a 6 cifre decimali (che rappresentano la parte frazionaria di un secondo).
- Z specifica l'ora UTC (fuso orario 0). Può essere specificato anche da +00:00, ma non da -00:00.
- (+|-)hh:mm specifica il fuso orario come differenza da UTC. (È necessario utilizzare + o -).
SELECT CAST (bag.bagInfo.bagArrivalDate AS Timestamp(3))
AS BAG_ARRIVING_DATE
FROM BaggageInfo bag WHERE bag.confNo=DN3I4Q
Spiegazione: il valore bagArrivalDate
è STRING. Utilizzando CAST si sta convertendo questo campo in un formato TIMESTAMP.
{"BAG_ARRIVING_DATE":"2019-02-15T21:21:00.000Z"}
SELECT fullName, bag.ticketNo,
bag.bagInfo[].bagArrivalDate
FROM BaggageInfo bag WHERE
exists bag.bagInfo[$element.bagArrivalDate >="2019-01-01T00:00:00"]
Spiegazione: si desidera filtrare e visualizzare i dettagli del bagaglio spedito dopo il 2019. La data di arrivo del sacchetto per ogni elemento nell'array flightLegs
viene confrontata con l'indicatore orario specificato (2019-01-01T00:00:00
). Qui il casting è implicito come bagArrivalDate
è un STRING ed è direttamente confrontato con un valore di Timestamp statico. Una funzione CAST esplicita non è necessaria quando è possibile eseguire un casting implicito. Tuttavia, i dati devono essere nel formato YYYY-MM-DDTHH:MI:SS
. Utilizzare quindi la condizione EXISTS per verificare se bagInfo è presente per questa condizione di indicatore orario.
{"fullName":"Kendal Biddle","ticketNo":1762377974281,"bagArrivalDate":"2019-03-05T12:00:00Z"}
{"fullName":"Lucinda Beckman","ticketNo":1762320569757,"bagArrivalDate":"2019-03-12T15:05:00Z"}
{"fullName":"Adelaide Willard","ticketNo":1762392135540,"bagArrivalDate":"2019-02-15T21:21:00Z"}
{"fullName":"Raymond Griffin","ticketNo":1762399766476,"bagArrivalDate":"2019-02-03T08:09:00Z"}
{"fullName":"Elane Lemons","ticketNo":1762324912391,"bagArrivalDate":"2019-03-15T10:13:00Z"}
{"fullName":"Zina Christenson","ticketNo":1762390789239,"bagArrivalDate":"2019-02-04T10:08:00Z"}
{"fullName":"Zulema Martindale","ticketNo":1762340579411,"bagArrivalDate":"2019-02-25T20:15:00Z"}
{"fullName":"Dierdre Amador","ticketNo":1762376407826,"bagArrivalDate":"2019-03-07T13:51:00Z"}
{"fullName":"Henry Jenkins","ticketNo":176234463813,"bagArrivalDate":"2019-03-02T13:18:00Z"}
{"fullName":"Rosalia Triplett","ticketNo":1762311547917,"bagArrivalDate":"2019-02-12T07:04:00Z"}
{"fullName":"Lorenzo Phil","ticketNo":1762320369957,"bagArrivalDate":["2019-03-12T15:05:00Z","2019-03-12T16:25:00Z"]}
{"fullName":"Gerard Greene","ticketNo":1762341772625,"bagArrivalDate":"2019-03-07T16:01:00Z"}
{"fullName":"Adam Phillips","ticketNo":1762344493810,"bagArrivalDate":"2019-02-01T16:13:00Z"}
{"fullName":"Doris Martin","ticketNo":1762355527825,"bagArrivalDate":"2019-03-22T10:17:00Z"}
{"fullName":"Joanne Diaz","ticketNo":1762383911861,"bagArrivalDate":"2019-02-16T16:13:00Z"}
{"fullName":"Teena Colley","ticketNo":1762357254392,"bagArrivalDate":"2019-02-13T11:15:00Z"}
{"fullName":"Michelle Payne","ticketNo":1762330498104,"bagArrivalDate":"2019-02-02T23:59:00Z"}
{"fullName":"Mary Watson","ticketNo":1762340683564,"bagArrivalDate":"2019-03-14T06:22:00Z"}
{"fullName":"Omar Harvey","ticketNo":1762348904343,"bagArrivalDate":"2019-03-02T16:09:00Z"}
{"fullName":"Fallon Clements","ticketNo":1762350390409,"bagArrivalDate":"2019-02-21T14:08:00Z"}
{"fullName":"Lisbeth Wampler","ticketNo":1762355854464,"bagArrivalDate":"2019-02-10T10:01:00Z"}
Espressioni trasformazione sequenza
Un'espressione di trasformazione di sequenza trasforma una sequenza in un'altra sequenza. Syntactically sembra una funzione il cui nome è seq_transform
. Il primo argomento è un'espressione che genera la sequenza da trasformare (la sequenza di input) e il secondo è un'espressione "mapper" calcolata per ogni elemento della sequenza di input. Il risultato dell'espressione seq_transform
è la concatenazione di sequenze prodotte da ogni valutazione dell'espressione mapper. L'espressione mapper può accedere all'elemento di input corrente tramite la variabile $.
ticketNo
, recuperare un array piatto contenente tutte le azioni eseguite sul bagaglio di tale ticketNo
.SELECT seq_transform(l.bagInfo[],
seq_transform(
$sq1.flightLegs[],
seq_transform(
$sq2.actions[],
{
"at" : $sq3.actionAt,
"action" : $sq3.actionCode,
"flightNo" : $sq2.flightNo,
"tagNum" : $sq1.tagNum
}
)
)
) AS actions
FROM baggageInfo l WHERE ticketNo=1762340683564
Spiegazione: è possibile utilizzare l'espressione di trasformazione della sequenza per trasformare i documenti JSON memorizzati nelle righe di tabella. In questi casi, si utilizzano spesso più espressioni di trasformazione di sequenza nidificate l'una all'altra. Qui l'espressione mapper di una trasformazione di sequenza interna potrebbe dover accedere all'elemento corrente di una trasformazione di sequenza esterna. Per consentire questo, ogni espressione di trasformazione di sequenza 'S' dichiara una variabile con il nome $sqN
, dove N è il livello di nidificazione dell'espressione S
all'interno delle espressioni di trasformazione di sequenza esterne. $sqN
è fondamentalmente un sinonimo di $
, ovvero è associato agli elementi restituiti dall'espressione di input S
. Tuttavia, è possibile accedere a $sqN
da altre espressioni di trasformazione di sequenza che possono essere nidificate all'interno dell'espressione S
.
{
"actions":[
{"action":"ONLOAD to HKG","at":"YYZ","flightNo":"BM267","tagNum":"17657806299833"},
{"action":"BagTag Scan at YYZ","at":"YYZ","flightNo":"BM267","tagNum":"17657806299833"},
{"action":"Checkin at YYZ","at":"YYZ","flightNo":"BM267","tagNum":"17657806299833"},
{"action":"Offload to Carousel at BLR","at":"BLR","flightNo":"BM115","tagNum":"17657806299833"},
{"action":"ONLOAD to BLR","at":"HKG","flightNo":"BM115","tagNum":"17657806299833"},
{"action":"OFFLOAD from HKG","at":"HKG","flightNo":"BM115","tagNum":"17657806299833"}
]
}
Esempi di espressioni SQL che utilizzano l'API QueryRequest
È possibile utilizzare l'API QueryRequest
e filtrare i dati da una tabella NoSQL utilizzando le espressioni SQL.
Per eseguire la query, utilizzare l'API NoSQLHandle.query()
.
//Fetch rows from the table
private static void fetchRows(NoSQLHandle handle,String sqlstmt) throws Exception {
try (
QueryRequest queryRequest = new QueryRequest().setStatement(sqlstmt);
QueryIterableResult results = handle.queryIterable(queryRequest)){
for (MapValue res : results) {
System.out.println("\t" + res);
}
}
}
String paran_expr="SELECT fullName, bag.bagInfo.tagNum, bag.bagInfo.routing, "+
"bag.bagInfo[].flightLegs[].fltRouteDest FROM BaggageInfo bag WHERE "+
"bag.bagInfo.flightLegs[].fltRouteSrc=any \"SFO\" AND "+
"(bag.bagInfo[].flightLegs[].fltRouteDest=any \"ATH\" OR "+
"bag.bagInfo[].flightLegs[].fltRouteDest=any \"JTR\" )";
System.out.println("Using Paranthesized expression ");
fetchRows(handle,paran_expr);
String case_expr="SELECT fullName,"+
"CASE WHEN NOT exists bag.bagInfo.flightLegs[0] "+
"THEN \"you have no bag info\" "+
"WHEN NOT exists bag.bagInfo.flightLegs[1] "+
"THEN \"you have one hop\" "+
"WHEN NOT exists bag.bagInfo.flightLegs[2] "+
"THEN \"you have two hops.\" "+
"ELSE \"you have three hops.\" "+
"END AS NUMBER_HOPS "+
"FROM BaggageInfo bag WHERE ticketNo=1762341772625";
System.out.println("Using Case Expression ");
fetchRows(handle,case_expr);
String seq_trn_expr="SELECT seq_transform(l.bagInfo[],"+
"seq_transform("+
"$sq1.flightLegs[],"+
"seq_transform("+
"$sq2.actions[],"+
"{"+
"\"at\" : $sq3.actionAt,"+
"\"action\" : $sq3.actionCode,"+
"\"flightNo\" : $sq2.flightNo,"+
"\"tagNum\" : $sq1.tagNum"+
"}"+
")"+
")"+
") AS actions FROM baggageInfo l WHERE ticketNo=1762376407826";
System.out.println("Using Sequence Transform Expressions ");
fetchRows(handle,seq_trn_expr);
Per eseguire la query, utilizzare il metodo borneo.NoSQLHandle.query()
.
# Fetch data from the table
def fetch_data(handle,sqlstmt):
request = QueryRequest().set_statement(sqlstmt)
print('Query results for: ' + sqlstmt)
result = handle.query(request)
for r in result.get_results():
print('\t' + str(r))
paran_expr = '''SELECT fullName, bag.bagInfo.tagNum, bag.bagInfo.routing,
bag.bagInfo[].flightLegs[].fltRouteDest FROM BaggageInfo bag
WHERE bag.bagInfo.flightLegs[].fltRouteSrc=any "SFO" AND
(bag.bagInfo[].flightLegs[].fltRouteDest=any "ATH" OR
bag.bagInfo[].flightLegs[].fltRouteDest=any "JTR" )'''
print('Using Paranthesized expression:')
fetch_data(handle,paran_expr)
case_expr = '''SELECT fullName,
CASE
WHEN NOT exists bag.bagInfo.flightLegs[0]
THEN "you have no bag info"
WHEN NOT exists bag.bagInfo.flightLegs[1]
THEN "you have one hop"
WHEN NOT exists bag.bagInfo.flightLegs[2]
THEN "you have two hops."
ELSE "you have three hops."
END AS NUMBER_HOPS
FROM BaggageInfo bag WHERE ticketNo=1762341772625'''
print('Using Case Expression:')
fetch_data(handle,case_expr)
seq_trn_expr = '''SELECT seq_transform(l.bagInfo[],
seq_transform(
$sq1.flightLegs[],
seq_transform(
$sq2.actions[],
{
"at" : $sq3.actionAt,
"action" : $sq3.actionCode,
"flightNo" : $sq2.flightNo,
"tagNum" : $sq1.tagNum
}
)
)
) AS actions FROM baggageInfo l WHERE ticketNo=1762376407826'''
print('Using Sequence Transform Expressions:')
fetch_data(handle,seq_trn_expr)
Per eseguire una query, utilizzare la funzione Client.Query
.
//fetch data from the table
func fetchData(client *nosqldb.Client, err error, tableName string, querystmt string)(){
prepReq := &nosqldb.PrepareRequest{
Statement: querystmt,
}
prepRes, err := client.Prepare(prepReq)
if err != nil {
fmt.Printf("Prepare failed: %v\n", err)
return
}
queryReq := &nosqldb.QueryRequest{
PreparedStatement: &prepRes.PreparedStatement, }
var results []*types.MapValue
for {
queryRes, err := client.Query(queryReq)
if err != nil {
fmt.Printf("Query failed: %v\n", err)
return
}
res, err := queryRes.GetResults()
if err != nil {
fmt.Printf("GetResults() failed: %v\n", err)
return
}
results = append(results, res...)
if queryReq.IsDone() {
break
}
}
for i, r := range results {
fmt.Printf("\t%d: %s\n", i+1, jsonutil.AsJSON(r.Map()))
}
}
paran_expr := `SELECT fullName, bag.bagInfo.tagNum, bag.bagInfo.routing,
bag.bagInfo[].flightLegs[].fltRouteDest FROM BaggageInfo bag
WHERE bag.bagInfo.flightLegs[].fltRouteSrc=any "SFO" AND
(bag.bagInfo[].flightLegs[].fltRouteDest=any "ATH" OR
bag.bagInfo[].flightLegs[].fltRouteDest=any "JTR" )`
fmt.Printf("Using Paranthesized expression:\n")
fetchData(client, err,tableName,paran_expr)
case_expr := `SELECT fullName,
CASE
WHEN NOT exists bag.bagInfo.flightLegs[0]
THEN "you have no bag info"
WHEN NOT exists bag.bagInfo.flightLegs[1]
THEN "you have one hop"
WHEN NOT exists bag.bagInfo.flightLegs[2]
THEN "you have two hops."
ELSE "you have three hops."
END AS NUMBER_HOPS
FROM BaggageInfo bag WHERE ticketNo=1762341772625`
fmt.Printf("Using Case Expression:\n")
fetchData(client, err,tableName,case_expr)
seq_trn_expr := `SELECT seq_transform(l.bagInfo[],
seq_transform(
$sq1.flightLegs[],
seq_transform(
$sq2.actions[],
{
"at" : $sq3.actionAt,
"action" : $sq3.actionCode,
"flightNo" : $sq2.flightNo,
"tagNum" : $sq1.tagNum
}
)
)
) AS actions FROM baggageInfo l WHERE ticketNo=1762376407826`
fmt.Printf("Using Sequence Transform Expressions:\n")
fetchData(client, err,tableName,seq_trn_expr)
Per eseguire una query, utilizzare il metodo query
.
//fetches data from the table
async function fetchData(handle,querystmt) {
const opt = {};
try {
do {
const result = await handle.query(querystmt, opt);
for(let row of result.rows) {
console.log(' %O', row);
}
opt.continuationKey = result.continuationKey;
} while(opt.continuationKey);
} catch(error) {
console.error(' Error: ' + error.message);
}
}
interface StreamInt {
acct_Id: Integer;
profile_name: String;
account_expiry: TIMESTAMP;
acct_data: JSON;
}
/* fetches data from the table */
async function fetchData(handle: NoSQLClient,querystmt: any) {
const opt = {};
try {
do {
const result = await handle.query<StreamInt>(querystmt, opt);
for(let row of result.rows) {
console.log(' %O', row);
}
opt.continuationKey = result.continuationKey;
} while(opt.continuationKey);
} catch(error) {
console.error(' Error: ' + error.message);
}
}
const paran_expr = `SELECT fullName, bag.bagInfo.tagNum, bag.bagInfo.routing,
bag.bagInfo[].flightLegs[].fltRouteDest FROM BaggageInfo bag
WHERE bag.bagInfo.flightLegs[].fltRouteSrc=any "SFO" AND
(bag.bagInfo[].flightLegs[].fltRouteDest=any "ATH" OR
bag.bagInfo[].flightLegs[].fltRouteDest=any "JTR" )`
console.log("Using Paranthesized expression");
await fetchData(handle,paran_expr);
const case_expr = `SELECT fullName,
CASE
WHEN NOT exists bag.bagInfo.flightLegs[0]
THEN "you have no bag info"
WHEN NOT exists bag.bagInfo.flightLegs[1]
THEN "you have one hop"
WHEN NOT exists bag.bagInfo.flightLegs[2]
THEN "you have two hops."
ELSE "you have three hops."
END AS NUMBER_HOPS
FROM BaggageInfo bag WHERE ticketNo=1762341772625`
console.log("Using Case Expression");
await fetchData(handle,case_expr);
const seq_trn_expr = `SELECT seq_transform(l.bagInfo[],
seq_transform(
$sq1.flightLegs[],
seq_transform(
$sq2.actions[],
{
"at" : $sq3.actionAt,
"action" : $sq3.actionCode,
"flightNo" : $sq2.flightNo,
"tagNum" : $sq1.tagNum
}
)
)
) AS actions FROM baggageInfo l WHERE ticketNo=1762376407826`
console.log("Using Sequence Transform Expressions");
await fetchData(handle,seq_trn_expr);
Per eseguire una query, è possibile chiamare il metodo QueryAsync
o chiamare il metodo GetQueryAsyncEnumerable
e ripetere l'iterazione sull'enumerabile asincrono risultante.
private static async Task fetchData(NoSQLClient client,String querystmt){
var queryEnumerable = client.GetQueryAsyncEnumerable(querystmt);
await DoQuery(queryEnumerable);
}
private static async Task DoQuery(IAsyncEnumerable<QueryResult<RecordValue>> queryEnumerable){
Console.WriteLine(" Query results:");
await foreach (var result in queryEnumerable) {
foreach (var row in result.Rows)
{
Console.WriteLine();
Console.WriteLine(row.ToJsonString());
}
}
}
private const string paran_expr =@"SELECT fullName, bag.bagInfo.tagNum, bag.bagInfo.routing,
bag.bagInfo[].flightLegs[].fltRouteDest FROM BaggageInfo bag
WHERE bag.bagInfo.flightLegs[].fltRouteSrc=any ""SFO"" AND
(bag.bagInfo[].flightLegs[].fltRouteDest=any ""ATH"" OR
bag.bagInfo[].flightLegs[].fltRouteDest=any ""JTR"" )";
Console.WriteLine("\nUsing Paranthesized expression:!");
await fetchData(client,paran_expr);
private const string case_expr =@"SELECT fullName,
CASE
WHEN NOT exists bag.bagInfo.flightLegs[0]
THEN ""you have no bag info""
WHEN NOT exists bag.bagInfo.flightLegs[1]
THEN ""you have one hop""
WHEN NOT exists bag.bagInfo.flightLegs[2]
THEN ""you have two hops.""
ELSE ""you have three hops.""
END AS NUMBER_HOPS
FROM BaggageInfo bag WHERE ticketNo=1762341772625";
Console.WriteLine("\nUsing Case Expression!");
await fetchData(client,case_expr);
private const string seq_trn_expr =@"SELECT seq_transform(l.bagInfo[],
seq_transform(
$sq1.flightLegs[],
seq_transform(
$sq2.actions[],
{
""at"" : $sq3.actionAt,
""action"" : $sq3.actionCode,
""flightNo"" : $sq2.flightNo,
""tagNum"" : $sq1.tagNum
}
)
)
) AS actions FROM baggageInfo l WHERE ticketNo=1762376407826" ;
Console.WriteLine("\nUsing Sequence Transform Expressions!");
await fetchData(client,seq_trn_expr);