haskellari / postgresql-simple

Mid-level client library for accessing PostgreSQL from Haskell
Other
88 stars 46 forks source link

Fail to parse values if inside function. #109

Closed diasbruno closed 1 year ago

diasbruno commented 1 year ago

If given a query like to returning

INSERT INTO a (b, c) VALUES (?, X(?))

It will fail to parse the template and no arguments are sent correctly.

cabal v2-test
Build profile: -w ghc-9.0.2 -O1
In order, the following will be built (use -v for more details):
 - Sdk-0.0.1 (test:SdkTests) (first run)
Preprocessing test suite 'SdkTests' for Sdk-0.0.1..
Building test suite 'SdkTests' for Sdk-0.0.1..
Running 1 test suites...
Test suite SdkTests: RUNNING...
### Error in:   Sdk:1:a test       
FormatError {
  fmtMessage = "syntax error in multi-row template", 
  fmtQuery = "INSERT INTO a (b, c) VALUES (?, DATE_TRUNC('seconds', ?)) RETURNING id, b, c", 
  fmtParams = []
}
Cases: 2  Tried: 2  Errors: 1  Failures: 0

Test suite SdkTests: FAIL
Test suite logged to:
/usr/local/src/source/sdk/dist-newstyle/build/x86_64-linux/ghc-9.0.2/Sdk-0.0.1/t/SdkTests/test/Sdk-0.0.1-SdkTests.log
0 of 1 test suites (0 of 1 test cases) passed.
cabal: Tests failed for test:SdkTests from Sdk-0.0.1.
diasbruno commented 1 year ago

I'll try to dig in to see where the parser is failing, but appreciate any suggestions if I'm doing something wrong.

phadej commented 1 year ago

Use query.

query is to returning what execute is to executeMany. I'm sorry this naming scheme is so confusing. We probably need to add clarifying docs. (queryMany would sound wrong though, so I understand why returning was made).

diasbruno commented 1 year ago

Thanks, @phadej. Interesting....

Let me know how can I help with the docs like what functions are recommended, and, which should be avoided/deprecated.