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

  • Home
  • SEARCH
  • 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 6204523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:06:31+00:00 2026-05-24T05:06:31+00:00

issue is this: in (pl)python code, we’ve calculated an integer = 26663. Can easily

  • 0

issue is this: in (pl)python code, we’ve calculated an integer = 26663.
Can easily convert this to hex using hex(myint) = 0x6827

So far so good!

Now, how to write this value -into a concatenation of strings- into a PostgreSQL (v9) bytea field? The DB is UTF8-encoded, if this matters.

EG, neither of these examples will work:

Here, of course, I cannot concatenate ‘str’ and ‘int’ objects:

rv = plpy.execute(plan, [ (string1 + 6827) ])

This one inputs the wrong hex code for 0x6827

rv = plpy.execute(plan, [ (string1 + str('6827')) ])

Help!

  • 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-24T05:06:32+00:00Added an answer on May 24, 2026 at 5:06 am

    I’m not familiar with Postgres, but the hex(n) function returns a string representation of the numeric value of n in hexadecimal. The nicest way in my opinion to concatenate this with a string is to use format strings. For example:

    rv = plpy.execute(plan, [ ( 'foo %s bar' % hex(6827) ) ] )
    

    If the string is really in a variable called string1, and you only need to append it with the hex value, then simple concatenation using the + sign will work fine:

    rv = plpy.execute(plan, [ ( string1 + hex(6827) ) ])
    

    This works without conversion because the hex() function returns a string.

    If you don’t actually want to store a printable string representation, but rather a binary string, use the struct module to create an array of bytes.

    import struct
    bytes = struct.pack('i', 6827) # Ignoring endianness
    

    A lot of people are confused about what storing something as “binary” actually means, and since you are using a field type (bytea) which seems to be intended for binary storage, maybe this is what you actually want?

    The returned value from bytes will be a string that you can either concatenate with another string, or continue to pack more binary values into.

    See the struct module documentation for more information!

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

Sidebar

Related Questions

I am using the Python code at the bottom of this question to send
I compiled python 2.6.4 for centos 5.3 and find this issue that os.path.getmtime() or
This issue is somewhat related: Problem with Code Generated by XSD.EXE: Sequence of Elements
I am 100% new to Python I am bumping into this weird issue regarding
In my Python code I often find myself doing the following (using DB-API): yValues
I am trying to convert my shell scripts into python code, but I am
I have a working Python 2.6 code using matplotlib, and would like to get
I got a small problem using pylint to check my python code. I use
The URL http://www.fourmilab.ch/cgi-bin/Earth shows a live map of the Earth. If I issue this
This issue came up when I got different records counts for what I thought

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.