lib / pq

Pure Go Postgres driver for database/sql
https://pkg.go.dev/github.com/lib/pq
MIT License
8.98k stars 909 forks source link

I encountered a problem when Using Go-pGSQL, which is as follows: #975

Closed mynameistian closed 4 years ago

mynameistian commented 4 years ago

Hi,friend:

I encountered a problem when Using Go-pGSQL, which is as follows:

Execute the SQL statement as follows:

Select * from books where price BETWEEN money(10)and Money (100)

In the use of Golang, the following error occurs:

The function money(Unknown) is not unique and cannot select the best candidate function

Please see the picture below for more information

QQ图片20200603232931

Looking forward to your reply

cbandy commented 4 years ago

The error is from the PostgreSQL server, not the client/driver:

psql> PREPARE stmt AS select money($1);
ERROR:  function money(unknown) is not unique
LINE 1: PREPARE stmt AS select money($1);
                               ^
HINT:  Could not choose a best candidate function. You might need to add explicit type casts.

As recommended in the error, use type casts:

psql> PREPARE stmt AS select $1::money;
PREPARE
mynameistian commented 4 years ago

Thank you. I've changed the money type to the numeric type.I don't think I can manage the type of money type right now.