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

Exposing the Field and table object ID's #363

Open
calledit opened this issue Apr 22, 2015 · 6 comments
Open

Exposing the Field and table object ID's #363

calledit opened this issue Apr 22, 2015 · 6 comments

Comments

@calledit
Copy link

Looking at:
http://www.postgresql.org/docs/current/static/protocol-message-formats.html
Scrolling down to:
RowDescription (B)

One can see that postgres does submit the id of the column & table of each result field.

looking at the function parseMeta:
https://github.com/lib/pq/blob/master/conn.go#L1401
We ignore the 6 bytes that is the column & table id could we expose these Id's in the api somehow? Or would that be hinderd by go's sql package?

@msakrejda
Copy link
Contributor

As far as I can tell, yes, that is among the many things that database/sql makes impossible (at least with any sensible API). Do you have any ideas on how we might expose this given the constraints of the interface?

@calledit
Copy link
Author

It is't a pretty solution but..

Something like adding a field_oid_hack=true parameter to the sql.Open string argument.

db, err := sql.Open("postgres", "user=pqgotest dbname=pqgotest field_oid_hack=true")

The parameter would cause the Rows.Columns() function to instead of just returning a column name return a comma separated string with all the interesting values.

@msakrejda
Copy link
Contributor

I think that could technically work but that's not what I would consider "a sensible API". Maybe a non-database/sql driver like pgx is a better fit for your use case? It seems to support this.

@calledit
Copy link
Author

No, i agree.
Had not seen that one before, definitely.

@johto
Copy link
Contributor

johto commented Apr 22, 2015

I wonder if we couldn't change database/sql to add a method to Rows() which would allows drivers to export an interface{} with additional information of their choosing. The patch should be relatively trivial, too.

@johto
Copy link
Contributor

johto commented Apr 22, 2015

I commented on golang/go/#5606 suggesting roughly the above. The issue has been open for quite some time, though, so I'm not sure if anything will come of it.

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

No branches or pull requests

3 participants