lxn / go-pgsql Goto Github PK
View Code? Open in Web Editor NEWA PostgreSQL client package for the Go Programming Language
License: Other
A PostgreSQL client package for the Go Programming Language
License: Other
Hello.
Could you make it clear - is it possible to perform bulk load of data via COPY table from stdin; statement using go-pgsql? If yes, how?
P.S.: Thank you for this project. You really filled an empty space of pure Go implementation of such important protocol.
I'll observe that another Go/PG binding is on GitHub, https://github.com/jbarham/pgsql.go, which take the alternative approach of wrapping libpq.
It handles the thread safety issue by implementing a connection pool mechanism.
I don't know if it's a better thing to try to merge code in one direction or another; I simply observe that it's worth taking a peek at it to see what's worth adapting in either direction.
CREATE TABLE test8 (aaa CHAR(10));
INSERT INTO test8 (aaa) VALUES ('aaaa');
rs,err := db.Query("SELECT aaa FROM test8")
error message:
Error: unexpected field data type
Getting this error for rs.Uint64() ; Error: parsing "9989608743": numerical result out of range
The type in DB is bigint.
Any help.
GS
Hello Alexander,
I have upgrade to go 1.3 and the code using your library errors with this sort of log :
2014/06/27 12:20:48 Error: write tcp 127.0.0.1:5432: i/o timeout
Stack Trace:
=======================================================
github.com/lxn/go-pgsql.panicIfErr (/Users/oayoun/Developer/go/src/github.com/lxn/go-pgsql/util.go, Line 9)
-------------------------------------------------------
github.com/lxn/go-pgsql.(*Conn).flush (/Users/oayoun/Developer/go/src/github.com/lxn/go-pgsql/conn_write.go, Line 18)
-------------------------------------------------------
github.com/lxn/go-pgsql.(*Conn).writeStartup (/Users/oayoun/Developer/go/src/github.com/lxn/go-pgsql/conn_write.go, Line 331)
-------------------------------------------------------
github.com/lxn/go-pgsql.Connect (/Users/oayoun/Developer/go/src/github.com/lxn/go-pgsql/conn.go, Line 324)
-------------------------------------------------------
vostok.(*Appserv).Start (/Users/oayoun/Developer/go/src/vostok/vostok.go, Line 2129)
-------------------------------------------------------
main.main (/Users/oayoun/Developer/go/src/hydra/server.go, Line 845)
-------------------------------------------------------
runtime.main (/_DEV/go/src/pkg/runtime/proc.c, Line 247)
-------------------------------------------------------
runtime.goexit (/_DEV/go/src/pkg/runtime/proc.c, Line 1445)
=======================================================
panic: [VOSTOK:vostok:Start] !!! could not start the database connection : write tcp 127.0.0.1:5432: i/o timeout !!!
I am currently looking into the issue within the source to find out what could have changed. I'll obviously keep you posted.
Oscar
I've written a test program for some of the database/sql packages. The others that I've tested to-date use a float64 for decimal values eg. "dbalance decimal(12,2) not null)" is scanned using a float64 as receiving value for the other 2 packages I've tested. From the testing that I've done, it would appear that this package uses big.Rat for decimal values. AFAIK and as determined from my testing to-date, float64 is perfectly adequate for decimal/currency values. In order to perform calculations, I convert them to an int64 to avoid rounding errors. I've partly altered my test program to cater for big.Rat,
I'm wondering if there is a particular reason for using big.Rat data-type instead of float64, and whether float64 may be more "standard"? I've partly implemented big.Rat in my test program, but thought it worth asking the question before completing the change, as float64 may have more general appeal.
I don't know if this driver implements the LastInsertId method of the Result type of the database/sql package or not but when I tried to use it I got back a 0 but in Postgres I could see the last ID was 98.
The way that I tried it out is as follows:
result, err := db.Exec("insert into commands (command,slot) values ($1,$2)", incoming.Command, incoming.Slot)
if err != nil {
l.Printf("Error inserting into the commands table: %v\n", err)
return
}
id, _ := result.LastInsertId()
fmt.Println(id) //Prints 0
apologies if this is incorrect...
Support on Execute for returning any generated keys as the result of statement. An example in Java would be:
Statement stmt = conn.createStatement(); stmt.execute(sql, Statement.RETURN_GENERATED_KEYS); ResultSet keyset = stmt.getGeneratedKeys();
I just start using pgsql and I like it. Good functionality and it seems to be pretty well documented. So thank you for that =)
But I don't like the directory layout introduced in commit (6cf4313). It's really cumbersome when installed with goinstall
, and in general it's a little more than necessary.
If installed with goinstall
, the import path in Go source files is really complicated and hard to remember.
import "github.com/lxn/go-pgsql/src/pkg/pgsql"
(It doesn't really make since to have a directory /src/
in the import path either, because you're importing a binary file.)
The source files (in /src/pkg/pgsql
) should be moved to /pgsql
. It is the Go convention. So it gives a shorter, easy to remember import path.
import "github.com/lxn/go-pgsql/pgsql"
I think the examples were good in the /examples
directory. The project wouldn't be cluttered, imho.
Please consider this. I think its really annoying the way it is. But otherwise, thanks again for this package! And please keep up the great work!
Is it possible if you would add, or at least explain, how go-pgsql expects querys with place holders to be done?
In my current code I am doing this:
tx, err := db.Begin()
stmt, err := tx.Prepare("insert into foo (number, value) values (?,?)")
if err != nil {
fmt.Println(err)
db.Close()
os.Exit(1)
}
derfer stmt.Close()
_, err = stmt.Exec("Twelve", 12)
if err != nil {
fmt.Println(err)
db.Close()
os.Exit(1)
}
tx.Commit()
Doing so gives this error:
Code: 42601
Message: syntax error at or near ","
Detail:
Hint:
Position: 39
Internal Position:
Internal Query:
Where:
File: scan.l
Line: 1001
Routine: scanner_yyerror
exit status 1
I am using go version weekly.2012-03-04 +5c664f190e4e as well as the database/sql package.
Link (https://github.com/lxn/go-pgsql/blob/master/go-pgsql/tree/master/examples) mentioned to examples in README is not working (returns 404)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.