1-- money check
2CREATE TABLE moneytmp (a money) WITH OIDS;
3\copy moneytmp from 'data/cash.data'
4SET enable_seqscan=on;
5SELECT count(*) FROM moneytmp WHERE a <  '22649.64';
6 count
7-------
8   289
9(1 row)
10
11SELECT count(*) FROM moneytmp WHERE a <= '22649.64';
12 count
13-------
14   290
15(1 row)
16
17SELECT count(*) FROM moneytmp WHERE a  = '22649.64';
18 count
19-------
20     1
21(1 row)
22
23SELECT count(*) FROM moneytmp WHERE a >= '22649.64';
24 count
25-------
26   254
27(1 row)
28
29SELECT count(*) FROM moneytmp WHERE a >  '22649.64';
30 count
31-------
32   253
33(1 row)
34
35SELECT a, a <-> '21472.79' FROM moneytmp ORDER BY a <-> '21472.79' LIMIT 3;
36     a      | ?column?
37------------+----------
38 $21,472.79 |    $0.00
39 $21,469.25 |    $3.54
40 $21,915.01 |  $442.22
41(3 rows)
42
43CREATE INDEX moneyidx ON moneytmp USING gist ( a );
44SET enable_seqscan=off;
45SELECT count(*) FROM moneytmp WHERE a <  '22649.64'::money;
46 count
47-------
48   289
49(1 row)
50
51SELECT count(*) FROM moneytmp WHERE a <= '22649.64'::money;
52 count
53-------
54   290
55(1 row)
56
57SELECT count(*) FROM moneytmp WHERE a  = '22649.64'::money;
58 count
59-------
60     1
61(1 row)
62
63SELECT count(*) FROM moneytmp WHERE a >= '22649.64'::money;
64 count
65-------
66   254
67(1 row)
68
69SELECT count(*) FROM moneytmp WHERE a >  '22649.64'::money;
70 count
71-------
72   253
73(1 row)
74
75EXPLAIN (COSTS OFF)
76SELECT a, a <-> '21472.79' FROM moneytmp ORDER BY a <-> '21472.79' LIMIT 3;
77                    QUERY PLAN
78--------------------------------------------------
79 Limit
80   ->  Index Only Scan using moneyidx on moneytmp
81         Order By: (a <-> '$21,472.79'::money)
82(3 rows)
83
84SELECT a, a <-> '21472.79' FROM moneytmp ORDER BY a <-> '21472.79' LIMIT 3;
85     a      | ?column?
86------------+----------
87 $21,472.79 |    $0.00
88 $21,469.25 |    $3.54
89 $21,915.01 |  $442.22
90(3 rows)
91
92