File: Select.hs

package info (click to toggle)
haskell-postgresql-simple 0.7.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 564 kB
  • sloc: haskell: 6,438; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 1,098 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{-# LANGUAGE OverloadedStrings #-}
module Main where

import           Database.PostgreSQL.Simple
import qualified Database.PostgreSQL.Simple.Vector as V
import qualified Database.PostgreSQL.Simple.Vector.Unboxed as VU

import           System.Environment (getArgs)
import           Data.Foldable (Foldable, foldl')
import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
    args <- getArgs
    conn <- connectPostgreSQL ""
    case args of
        ("vector":_) -> do
            result <- V.query_ conn "SELECT * FROM generate_series(1, 10000000);"
            print (process result)
        ("unboxed":_) -> do
            -- dummy column
            result <- VU.query_ conn "SELECT (NULL :: VOID), * FROM generate_series(1, 10000000);"
            print (process' result)
        _ -> do
            result <- query_ conn "SELECT * FROM generate_series(1, 10000000);"
            print (process result)

process :: Foldable f => f (Only Int) ->  Int
process = foldl' (\x (Only y) -> max x y) 0

process' :: VU.Vector ((), Int) ->  Int
process' = VU.foldl' (\x (_, y) -> max x y) 0