Reputation: 2931
My schema:
CREATE TABLE IF NOT EXISTS feed (
id SERIAL PRIMARY KEY CHECK (id > 0),
name TEXT NOT NULL,
url TEXT NOT NULL
);
My code:
{-# LANGUAGE OverloadedStrings #-}
import Database.PostgreSQL.Simple
hello :: IO String
hello = do
conn <- connectPostgreSQL ""
[Only i] <- query_ conn "SELECT url FROM feed WHERE id = 1"
return i
main :: IO ()
main = hello >>= print
My error:
user error (Pattern match failure in do expression at src/Main.hs:8:3-10)
My questions:
Update: I connected to the wrong database and therefor my assumption about the result set was wrong. It contained zero lines instead of one line and thus it tried to match []
against [Only i]
. I found it out by executing the query in ghci:
:set -XOverloadedStrings
import Database.PostgreSQL.Simple
do; conn <- connectPostgreSQL "" ;query_ conn "SELECT url FROM feed WHERE id = 1"
Upvotes: 0
Views: 245