question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there some kind of mapping a data type's oid to its name?

See original GitHub issue

Driver version

2.0.905

Redshift version

PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.36224��

Client Operating System

Darwin Nativs-MacBook-Pro.local 21.4.0 Darwin Kernel Version 21.4.0: Mon Feb 21 20:34:37 PST 2022; root:xnu-8020.101.4~2/RELEASE_X86_64 x86_64

Python version

3.8.7

Problem description

I was wondering if there is some a way for to convert a data type type_oid into string instead.

cursor.execute("SELECT int_col from some_table")
description = cursor.description
oid = description[0][1]
print(oid)  # will print oid. for the sake of example let's say it's 1
print(some_func(oid)). # "int"

in psycopg2 there is the https://www.psycopg.org/docs/extensions.html#psycopg2.extensions.string_types

so I’m looking for something similar, but for redshift data types.

Thanks in advance!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
Brooke-whitecommented, Jul 1, 2022

Hi @ni-todo-spot – we’ve just released v2.0.908 which includes support for this feature as noted above.

from redshift_connector.utils.oids import get_datatype_name
get_datatype_name(1266)
Out[3]: 'TIMETZ'
get_datatype_name(23)
Out[4]: 'INTEGER'

I’ll be closing this issue but feel free to open a new one if you see any issue with this feature or need any help. Thanks again for working with us to improve redshift-connector! 😃

3reactions
Brooke-whitecommented, Jun 28, 2022

Hey @ni-todo-spot,

To clarify my second comment a bit, these IN/OUT function mappings are defined for Redshift, not postgres despite their name starting with pg_ (we need to fix this, I’m hoping to fit in our next release).

I took a look into implementing this yesterday and came up with an approach using IntEnum that will provide the desired functionality and clean up our codebase a bit. Here’s an example of how it will work

Python 3.9.0 (v3.9.0:9cf6752276, Oct  5 2020, 11:29:23) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.
PyDev console: using IPython 7.19.0
Python 3.9.0 (v3.9.0:9cf6752276, Oct  5 2020, 11:29:23) 
[Clang 6.0 (clang-600.0.57)] on darwin
from redshift_connector.utils.oids import get_datatype_name
get_datatype_name(1266)
Out[3]: 'TIMETZ'
get_datatype_name(23)
Out[4]: 'INTEGER'

We should be able to get this in our release scheduled for July 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation: 15: 8.19. Object Identifier Types - PostgreSQL
Object identifiers (OIDs) are used internally by PostgreSQL as primary keys for various system tables. Type oid represents an object identifier. There are ......
Read more >
ArcGIS field data types
The types are matched to the closest data type available in the DBMS. This process is referred to as data type mapping.
Read more >
Elasticsearch Mapping Basics & Examples (After Create Index)
First, let's look at indexing according to document type. Indices are independent from one another, so you can use the same name for...
Read more >
Data Type Mapping between Active Directory and LDAP
Friendly syntax name LDAP syntax OID ADSTYPEENUM data type AccessPointDN 1.3.6.1.4.1.1466.115.121.1.2 ADSTYPE_CASE_IGNORE_STRING AttributeTypeDescription 1.3.6.1.4.1.1466.115.121.1.3 ADSTYPE_CASE_IGNORE_STRING Audio 1.3.6.1.4.1.1466.115.121.1.4 ADSTYPE_OCTET_STRING
Read more >
3 Defining Object Types for Data Cartridges
Each type has an OID . If you create an object type and do not specify an OID , Oracle generates an OID...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found