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 6121665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:48:36+00:00 2026-05-23T15:48:36+00:00

I have a table with a bytea field, and it would be convenient if

  • 0

I have a table with a bytea field, and it would be convenient if I could do queries via the command line (or pgAdmin’s query executor). I’ve got the hex value as a string. Is there a built in function to convert hex to bytea?

I’d like to do something like:

SELECT * FROM table WHERE my_bytea_field=some_???_function('fa26e312');

where ‘fa26e312’ is the hex value of the bytea field I want.

Note: this is just to be helpful while I’m developing / debugging things, I can do it via code but I’d like to be able to do it by hand in a query.

  • 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-23T15:48:36+00:00Added an answer on May 23, 2026 at 3:48 pm

    Try using built-in decode(string text, type text) function (it returns bytea). You can run queries via CLI using psql in non-interactive mode, that is with -c switch (there are some formatting options if you like):

    psql -c "SELECT * FROM table WHERE my_bytea_field=decode('fa26e312', 'hex');"
    

    Example:

    CREATE TABLE test(id serial, my_bytea_field bytea);
    INSERT INTO test (my_bytea_field) VALUES
        (E'\\320\\170'::bytea),
        (E'\\100\\070'::bytea),
        (E'\\377\\377'::bytea);
    
    psql -tc "SELECT * FROM test WHERE my_bytea_field=decode('ffff', 'hex');"
      3 | \377\377
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with a blob field that stores photos in jpg format.
I have a table called Basic , start_time is one field with type :VARCHAR(5),
I have a table with a VARBINARY(MAX) field (SQL Server 2008 with FILESTREAM )
I have a field in a table that is varchar2, 4000 bytes. There are
I have a table with a nullable field of type text. When I run
I have table inside a div tab. The table has 40 rows in it
I have table with 50 entries (users with such details like Name Surname Location
I have table rows of data in html being filled from a CGI application.
I have table with some fields that the value will be 1 0. This
i have table structure with 3 colums (column1, column2, column3) and i want to

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.