On this page:
aggregate
scalar
sql
val
??
6.2.1 Clauses
select
where
group-by
having
order-by
join-on
6.2.2 Aggregates
avg
min
max
sum
count
6.2.3 Misc
exists
subquery
coalesce
round
6.2.4 Date Math
date+
date-
years
months
days
hours
minutes
seconds
6.2.5 Operators
and
or
not
=
<>
<
<=
>
>=
like
not-like
is
is-not
+
-
*
/

6.2 plisqin-lib/unsafe🔗ℹ

procedure

aggregate : 
(token-constructor
 [unsafe-content? ...+ -> Scalar?])
A primitive building block with no strict counterpart. Constructs an arbitrary fragment of SQL that represents an aggregate operation. This fragment will recognize grouped joins like the built-in aggregates, such as %%count or %%max. Let’s show the maximum UnitPriceDiscount we’ve ever given for each Product, and add 42 just for fun:
> (define (%%max-plus-42 . tokens)
    (%%aggregate "max(" tokens ") + 42"))

> (aw:show-table
   (from p Product
         (join detailsG SalesOrderDetail
               (group-by (ProductID detailsG))
               (join-on (.= (ProductID detailsG)
                            (ProductID p))))
         (select (ProductName p))
         (select (%%max-plus-42 (UnitPriceDiscount detailsG)))
         (limit 3)))

Show TableShow SQL

select p.Name as ProductName

  , detailsG.__INJECT1

from Product p

inner join (

  select detailsG.ProductID as __INJECT0

    , max(detailsG.UnitPriceDiscount) + 42 as __INJECT1

  from SalesOrderDetail detailsG

  group by detailsG.ProductID

) detailsG

   on (detailsG.__INJECT0 = p.ProductID)

limit 3

ProductName

__INJECT1

Sport-100 Helmet, Red

42.15

Sport-100 Helmet, Black

42.15

Mountain Bike Socks, M

42.1

procedure

scalar : 
(token-constructor
 [unsafe-content? ...+ -> Scalar?])
A primitive building block with no strict counterpart. Constructs an arbitrary fragment of SQL that represents a scalar. This fragment will be injected into a grouped join if needed. In the example on %%aggregate, notice that (ProductID detailsG) occurs in a join-on clause of a grouped join. This is why it appears as "__INJECT0" in the generated SQL. This behavior is enabled because (ProductID detailsG) is returning a %%scalar. Although every %%scalar should be a Scalar?, the type Scalar? is irrelevant to this behavior.

procedure

sql : 
(token-constructor
 [unsafe-content? ...+ -> Token?])
A primitive building block with no strict counterpart. Constructs an arbitrary fragment of SQL with no special behavior.

procedure

(val x [type])  Token?

  x : (or/c number? string? boolean?)
  type : (or/c #f type?) = #f
Converts a Racket value into a Token?. The token’s nullability is always no. If type is #f, it is inferred as follows:
> (Number? (%%val 42))

#t

> (String? (%%val "hello world"))

#t

> (Bool? (%%val #t))

#t

If type is not #f, the return value will be cast to it:
> (Datetime? (%%val "1999-12-31" Datetime?))

#t

procedure

(?? token-1 [token-N ...+] [/fallback])

 
  token-1 : Token?
  token-N : Token?
  /fallback : fallback?
This procedure is typically used to attach a fallback, but it can also be used as a synonym for %%coalesce if no fallback is given. More precisely, this procedure has 3 cases:
  1. When given two arguments and the last argument is a fallback?, it simply attaches the fallback to the first argument:
    (?? token-1 /fallback)
    ; is equivalent to
    (>> token-1 #:fallback /fallback)

  2. When given more than two arguments and the last argument is a fallback?, it attaches the fallback to the result of %%coalesce:
    (?? token-1 token-N ...+ /fallback)
    ; is equivalent to
    (>> (%%coalesce token-1 token-N ...+) #:fallback /fallback)

  3. When the last argument is not a fallback?, it is simply a synonym for %%coalesce:
    (?? token-1 token-N ...+)
    ; is equivalent to
    (%%coalesce token-1 token-N ...+)

You may need to check the documentation on %%coalesce to know the return type of cases 2 and 3.

6.2.1 Clauses🔗ℹ

procedure

select : 
(token-constructor
 [unsafe-content? ...+ -> Select?])

Unsafe variant of select.

procedure

where : 
(token-constructor
 [unsafe-content? ...+ -> Where?])

Unsafe variant of where.

procedure

group-by : 
(token-constructor
 [unsafe-content? ...+ -> GroupBy?])

Unsafe variant of group-by.

procedure

having : 
(token-constructor
 [unsafe-content? ...+ -> Having?])

Unsafe variant of having.

procedure

order-by : 
(token-constructor
 [unsafe-content? ...+ -> OrderBy?])

Unsafe variant of order-by.

procedure

join-on : 
(token-constructor
 [unsafe-content? ...+ -> JoinOn?])

Unsafe variant of join-on.

6.2.2 Aggregates🔗ℹ

procedure

avg : 
(token-constructor
 [unsafe-content? ...+ -> Number?])

Unsafe variant of avg.

procedure

min : 
(token-constructor
 [unsafe-content? ...+ -> Scalar?])

Unsafe variant of min.

procedure

max : 
(token-constructor
 [unsafe-content? ...+ -> Scalar?])

Unsafe variant of max.

procedure

sum : 
(token-constructor
 [unsafe-content? ...+ -> Number?])

Unsafe variant of sum.

procedure

count : 
(token-constructor
 [unsafe-content? ...+ -> Number?])

Unsafe variant of count.

6.2.3 Misc🔗ℹ

procedure

exists : 
(token-constructor
 [unsafe-content? ...+ -> Bool?])

Unsafe variant of exists.

procedure

subquery : 
(token-constructor
 [unsafe-content? ...+ -> Subquery?])

Unsafe variant of subquery.

procedure

coalesce : 
(token-constructor
 [unsafe-content? unsafe-content? ...+ -> Scalar?])

Unsafe variant of coalesce.

procedure

round : 
(token-constructor
 [unsafe-content? ...+ -> Number?])

Unsafe variant of round.

6.2.4 Date Math🔗ℹ

procedure

date+ : 
(token-constructor
 [unsafe-content? interval? ...+ -> Datetime?])

Unsafe variant of date+.

procedure

date- : 
(token-constructor
 [unsafe-content? interval? ...+ -> Datetime?])

Unsafe variant of date-.

procedure

years : 
(token-constructor
 [unsafe-content? -> interval?])

Unsafe variant of years.

procedure

months : 
(token-constructor
 [unsafe-content? -> interval?])

Unsafe variant of months.

procedure

days : 
(token-constructor
 [unsafe-content? -> interval?])

Unsafe variant of days.

procedure

hours : 
(token-constructor
 [unsafe-content? -> interval?])

Unsafe variant of hours.

procedure

minutes : 
(token-constructor
 [unsafe-content? -> interval?])

Unsafe variant of minutes.

procedure

seconds : 
(token-constructor
 [unsafe-content? -> interval?])

Unsafe variant of seconds.

6.2.5 Operators🔗ℹ

procedure

and : 
(token-constructor
 [unsafe-content? ...+ -> Bool?])

Unsafe variant of and.

procedure

or : 
(token-constructor
 [unsafe-content? ...+ -> Bool?])

Unsafe variant of or.

procedure

not : 
(token-constructor
 [unsafe-content? ...+ -> Bool?])

Unsafe variant of not.

procedure

= : 
(token-constructor
 [unsafe-content? ...+ -> Bool?])

Unsafe variant of =.

procedure

<> : 
(token-constructor
 [unsafe-content? ...+ -> Bool?])

Unsafe variant of <>.

procedure

< : 
(token-constructor
 [unsafe-content? ...+ -> Bool?])

Unsafe variant of <.

procedure

<= : 
(token-constructor
 [unsafe-content? ...+ -> Bool?])

Unsafe variant of <=.

procedure

> : 
(token-constructor
 [unsafe-content? ...+ -> Bool?])

Unsafe variant of >.

procedure

>= : 
(token-constructor
 [unsafe-content? ...+ -> Bool?])

Unsafe variant of >=.

procedure

like : 
(token-constructor
 [unsafe-content? ...+ -> Bool?])

Unsafe variant of like.

procedure

not-like : 
(token-constructor
 [unsafe-content? ...+ -> Bool?])

Unsafe variant of not-like.

procedure

is : 
(token-constructor
 [unsafe-content? unsafe-content? -> Bool?])

Unsafe variant of is.

procedure

is-not : 
(token-constructor
 [unsafe-content? unsafe-content? -> Bool?])

Unsafe variant of is-not.

procedure

+ : 
(token-constructor
 [unsafe-content? ...+ -> Scalar?])

Unsafe variant of +.

procedure

- : 
(token-constructor
 [unsafe-content? ...+ -> Scalar?])

Unsafe variant of -.

procedure

* : 
(token-constructor
 [unsafe-content? ...+ -> Scalar?])

Unsafe variant of *.

procedure

/ : 
(token-constructor
 [unsafe-content? ...+ -> Scalar?])

Unsafe variant of /.