Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6995439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:01:29+00:00 2026-05-27T20:01:29+00:00

psycopg2 converts NULL to None through the NoneAdapter (right?) How do I create another

  • 0

psycopg2 converts NULL to None through the NoneAdapter (right?)
How do I create another adapter that converts all NULL to a string ‘NA’ ?

Thanks

*UPDATE:
@thatisbrilliant
Here is what i have:
After doing this query :

SELECT pg_type.oid
FROM pg_type JOIN pg_namespace
    ON typnamespace = pg_namespace.oid
WHERE typname = 'point'
    AND nspname = 'pg_catalog';  

and get the point_oid = 600 so I continue with this:

def NA(value, cur):
    if value is None:
        return 'NA'
    return value
None2NA = psycopg2.extensions.new_type((600,), 'None2NA', NA)
psycopg2.extensions.register_type(None2NA)  

Doesn’t work o.o it still returns None

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:01:30+00:00Added an answer on May 27, 2026 at 8:01 pm

    Actually NoneAdapter does the opposite of what you want, converts python’s None type into SQL NULL. For info on casting SQL types into python objects, check out the official psycopg2 documentation.

    Based on that, it looks like you will have to register your adapter function for every type you want it to work on, but I assume the function would simply be:

    def NA(value, cur):
        if value is None:
            return 'NA'
        return value
    

    Then register with psycopg2.extensions.new_type and psycopg2.extensions.register_type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use psycopg2 for accessing my postgres database in python. My function should create
I am having the same problem as: python adds "E" to string All the
I'm using psycopg2 to access a postgresql 8.4 database, and on an update query
After going through hell trying to install the latest version of postgresql and psycopg2
I have a Django-based webapp that is using PostgreSQL as the backend via psycopg2.
I am working on PostgreSQL and psycopg2. Trying to get feed data which is
I have Pythong2.6, psycopg2 and pgAdmin3 installed using Macports. My settings.py is: DATABASE_ENGINE =
I'm getting an error whilst trying to install psycopg2 on ubuntu 9.10 64 bit.
I'm trying to install psycopg2, using pip, on Fedora. I get the message: pg_config
I'm having strange error with installing fixture from dumped data. I am using psycopg2,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.