-
I may have this wrong but did something change in this type? Doc indicates there is a DataTypeName string? d.DataTypeName undefined (type pgconn.FieldDescription has no field or method DataTypeName) import "github.com/jackc/pgx/v5" I'm trying to assert data types |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
I think you are looking at the v3 docs. That doesn't exist in v4 or v5. https://pkg.go.dev/github.com/jackc/pgx/[email protected]/pgconn#FieldDescription. The protocol doesn't directly expose the type name. Only the OID. You may be able to get the |
Beta Was this translation helpful? Give feedback.
-
yeah that goes to v3 what I was looking at .... I see now you do have newer. Google is my friendemy right. |
Beta Was this translation helpful? Give feedback.
-
Going into the future will FieldDescription name continue to exist as it does now? Can I depend on that or will there be an alternative? |
Beta Was this translation helpful? Give feedback.
-
I have the DataTypeOID fine but ...
} |
Beta Was this translation helpful? Give feedback.
-
Everything is still available, but usually now via method instead of an exposed field. https://pkg.go.dev/github.com/jackc/pgx/v5/pgconn#PgConn.PID ... https://pkg.go.dev/github.com/jackc/pgx/v5#Conn.TypeMap gets you the pgtype.Map. From there you can call TypeForOID. It is only a map lookup. It is not a database query. |
Beta Was this translation helpful? Give feedback.
-
I got the oid from the field description then cobbled a switch with some known oids then using reflect.TypeOf in default rapidly exposed the small set of asserts. Adding new oids to case sets as I went.Pgtype.numeric Interface{} Are 2 that came up requiring research.I’ll look through the Conn.TypeMap you have suggested to see if it works better.Thanks for your time in this I have a working postgres to document db converter. Well almost.WaltSent from my iPadOn Sep 11, 2023, at 11:00 AM, Jack Christensen ***@***.***> wrote:
Everything is still available, but usually now via method instead of an exposed field.
https://pkg.go.dev/github.com/jackc/pgx/v5/pgconn#PgConn.PID
https://pkg.go.dev/github.com/jackc/pgx/v5/pgconn#PgConn.SecretKey
https://pkg.go.dev/github.com/jackc/pgx/v5/pgconn#PgConn.ParameterStatus
...
https://pkg.go.dev/github.com/jackc/pgx/v5#Conn.TypeMap gets you the pgtype.Map. From there you can call TypeForOID. It is only a map lookup. It is not a database query.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Looks like the TypeMap codec method PreferredFormat() returns bool not the int16 format code. I get 1 and 0. Is that even the right method?To convert the column values generated by the next to go values I need to…PlanScan()ThenDecodeValue()?What is the format parameter and how do I provide it?ThanksWaltSent from my iPadOn Sep 11, 2023, at 11:00 AM, Jack Christensen ***@***.***> wrote:
Everything is still available, but usually now via method instead of an exposed field.
https://pkg.go.dev/github.com/jackc/pgx/v5/pgconn#PgConn.PID
https://pkg.go.dev/github.com/jackc/pgx/v5/pgconn#PgConn.SecretKey
https://pkg.go.dev/github.com/jackc/pgx/v5/pgconn#PgConn.ParameterStatus
...
https://pkg.go.dev/github.com/jackc/pgx/v5#Conn.TypeMap gets you the pgtype.Map. From there you can call TypeForOID. It is only a map lookup. It is not a database query.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
https://pkg.go.dev/github.com/jackc/pgx/[email protected]/pgtype#Map.FormatCodeForOID and all the implementers of PreferredFormat return int16 not bool...
1 and 0 are the underlying values for the binary and text format respectively.
Something like that is possible... but unless you are doing something very unusual you shouldn't need to be working at that low level. You could call |
Beta Was this translation helpful? Give feedback.
yeah that goes to v3 what I was looking at .... I see now you do have newer. Google is my friendemy right.
TypeForOid ok I see that will have to see how to get the oid at first glance that looks like a query which is too far to go I think.
Is the OID available in pgx internals?
Thanks