Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot unmarshal number into Go value of type map[string]interface {} #54

Closed
bera-josh-jewell opened this issue Feb 17, 2022 · 6 comments · Fixed by #76
Closed

cannot unmarshal number into Go value of type map[string]interface {} #54

bera-josh-jewell opened this issue Feb 17, 2022 · 6 comments · Fixed by #76

Comments

@bera-josh-jewell
Copy link

I am just trying to get through a basic tutorial. I installed through go install:
go install github.com/jschaf/pggen/cmd/pggen@latest

Then tried to run the following command against my postgres database:
pggen gen go \ --schema-glob author/schema.sql \ --query-glob author/query.sql

it creates the author schema in the database correctly, but I get the following error while trying to generate code for query.sql:
ERROR: parse template query file "C:\\code\\api-brand-allocation\\author\\query.sql": infer typed named query FindAuthorByID: infer output types for query: infer output type nullability: explain prepared query: can't scan into dest[0]: json: cannot unmarshal number into Go value of type map[string]interface {}
I pulled my query.sql and schema.sql from the following location:
https://github.com/jschaf/pggen/tree/main/example/author

Can't figure out what I missed, hopefully something simple. Thanks!

@jschaf
Copy link
Owner

jschaf commented Feb 17, 2022

I just verified that installing via go install and running the author example works on main:

go install github.com/jschaf/pggen/cmd/pggen@latest
cd pggen/example
~/go/bin/pggen gen go --schema-glob author/schema.sql --query-glob author/query.sql

Does running the example from the repo work? My guess is that either schema file or query file has changed. The author example doesn't use json so that's odd. Can you verify the content hasn't changed?

@bera-josh-jewell
Copy link
Author

bera-josh-jewell commented Feb 17, 2022

thanks so much for getting back to me. I just pulled the repo and then tried again. I am getting the same error. It is really odd it's complaining about json. Is that how it serializes the data?

Here is my error
image

Could this have anything to do with me running on windows?

@jschaf
Copy link
Owner

jschaf commented Feb 17, 2022

I’d suspect the database setup before blaming Windows. Pggen mostly just connects to Postgres

You’ll need Docker to run pggen without a Postgres connection. If the Docker approach works it’s probably the DB setup.

@bera-josh-jewell
Copy link
Author

Just wanted to report back that using the docker image for postgres seemed to do the trick. Any guesses on what could be causing an issue with our existing database server?

@jschaf
Copy link
Owner

jschaf commented Feb 18, 2022

Any guesses on what could be causing an issue with our existing database server?

What's the output if you run the pggen queries manually, replacing the pggen.arg with a value? It might also help to add some data to the table to see the shape of data.

@jschaf
Copy link
Owner

jschaf commented May 30, 2022

Going to close as issue was resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants