Comments (8)
Here's an excessively verbose example since I don't know what error you are getting or where you are stuck (please be more specific):
package main
import (
_ "github.com/bmizerany/pq"
"database/sql"
"fmt"
)
func main() {
db, err := sql.Open("postgres",
"user=XXX dbname=XXX host=XXX")
if err != nil {
panic(err)
}
fetch, err := db.Query(`select url_decode($1::text)`,`%66%6F%6F`)
if err != nil {
panic(err)
}
var s string
for fetch.Next() {
err = fetch.Scan(&s)
if err != nil {
panic(err)
}
fmt.Println(s)
}
}
url_decode is this: http://postgres.cz/wiki/PostgreSQL_SQL_Tricks#Function_for_decoding_of_url_code
from pq.
On 12/17/2012 07:17 PM, myannikos wrote:
Here's an excessively verbose example since I don't know what error you
are getting or where you are stuck (please be more specific):
Frankly I didn't tried before but I did not find any example on using
stored procedures with Golang sql/pq so I asked before. So calling a SP
is more or less the same as 1. binding the parameters 2. executing 3.
fetching the returns as with any "regular" select / update / insert?
slightly OT but anyway ... back in the days our DB admins advised us to
use SPs even for "simple" things because of their performance gain
(pre-parsed syntax, execution plan, ...). Is this still true?
package main
import (
_ "github.com/bmizerany/pq"
"database/sql"
"fmt"
)func main() {
db, err := sql.Open("postgres", "user=XXX dbname=XXX host=XXX") if err != nil { panic(err) } fetch, err := db.Query(`select url_decode($1::text)`,`%66%6F%6F`) if err != nil { panic(err) } var s string for fetch.Next() { err = fetch.Scan(&s) if err != nil { panic(err) } fmt.Println(s) }
}
url_decode is this:
http://postgres.cz/wiki/PostgreSQL_SQL_Tricks#Function_for_decoding_of_url_code—
Reply to this email directly or view it on GitHub
https://github.com/bmizerany/pq/issues/62#issuecomment-11453085.
from pq.
@the42 the bug reporting form is not a QnA service, ref #61 also. It is a database of misbehavior.
Most postgres drivers are completely unaware of stored procedures: by and large, they only care about query text, return types, and parameters. So, there is no reason they should't work.
Any performance advantages of LANGUAGE SQL
(which is importantly not the same as LANGUAGE plpgsql
) stored procedures can be captured with prepared statements. There can benefits in avoiding network round trips for procedural code though. One may also find their logs easier to read this way, by ascribing symbolic names to queries.
There are some software engineering advantages to LANGUAGE SQL
functions (use by different applications, reading logs, use from an interactive tool like psql
, dependency tracking and static analysis at creation time), but there are some cost (having to name things, synchronizing the state between code and the operators installed, versioning) also. What choice of trade-offs works best for your project is up to you, but both are workable and used often.
from pq.
On 28.12.2012 01:38, Daniel Farina wrote:
@the42 https://github.com/the42 the bug reporting form is not a QnA
service, ref #61 https://github.com/bmizerany/pq/issues/61 also. It
is a database of misbehavior.I am really sorry for this abuse I did after misreading
https://github.com/bmizerany/pq/issues/21#issuecomment-5941855Most postgres drivers are completely unaware of stored procedures: by
and large, they only care about query text, return types, and
parameters. So, there is no reason they should work.Last thing: Reading in context I guess you meant "So, there is no reason
they should NOT work."
Thank you for in detail replies. @daniel & @blakeAny performance advantages of |LANGUAGE SQL| (which is importantly not
the same as |LANGUAGE plpgsql|) stored procedures can be captured with
prepared statements. There can benefits in avoiding network round
trips for procedural code though. One may also find their logs easier
to read this way, by ascribing symbolic names to queries.There are some software engineering advantages to |LANGUAGE SQL|
functions (use by different applications, reading logs, use from an
interactive tool like |psql|, dependency tracking and static analysis
at creation time), but there are some cost (having to name things,
synchronizing the state between code and the operators installed,
versioning) also. What choice of trade-offs works best for your
project is up to you, but both are workable and used often.—
Reply to this email directly or view it on GitHub
https://github.com/bmizerany/pq/issues/62#issuecomment-11722393.
from pq.
Last thing: Reading in context I guess you meant "So, there is no reason
they should NOT work."
Yeah, sorry about the error.
Don't sweat using the bug reports to get help; it mostly signifies there's not much other way to do it. I suppose I only wish you had tried it and reported a detailed issue (which, in my thinking, you wouldn't have had), first.
I will probably open a mailing list for this kind of correspondence.
from pq.
I've also edited the above text (shouldn't vs should) to be more clear for the archives.
from pq.
This work for me, Greetings
fmt.Print("inserting Persona => ")
sqlStatement := "select * from crear_persona('" + persona.Ci + "','" + persona.Nombre + "','" + persona.App + "','" + persona.Apm + "','" + persona.Cuenta + "','" + persona.Contrasenia + "','" + persona.Estado + "')"
_, err := db.Exec(sqlStatement)
if err != nil {
fmt.Println("Error inserting Persona")
fmt.Println(err)
panic(err)
}
fmt.Println("Persona inserted")
from pq.
@victorhugoviiii I sure do hope that was a joke! (A bad joke at that!)
from pq.
Related Issues (20)
- ▄
- lib/pq incorrectly escapes input strings that are already escaped
- v1.10.8 break if .pgpass contains empty line HOT 1
- v1.10.8 got undefined: driver.Validator HOT 2
- Potential leak in notify.go HOT 1
- Unable to parse arrays that are not 1-based
- Array types can't convert {NULL} HOT 2
- Does pg not support integer type?
- converting NULL to string is unsupported
- [docs] Add example of multiple parallel listeners HOT 1
- Tx.Rollback returns ErrBadConn after context is cancelled
- Connection string parsing fails randomly HOT 2
- 1 Listener for 2 channel HOT 1
- SonarCloud Vulnerability: Make sure this PostgreSQL database password gets changed and removed from the code.
- Usage of COPY TO STDOUT WITH CSV
- RFC 9266: Channel Bindings for TLS 1.3 support
- Query extra_float_digits problem
- Is Postgres15.4 is compatible with the lib/pq package?
- What kind of mistake is this?
- how to deal with "cached plan must not change result type" error?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pq.