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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:00:44+00:00 2026-05-29T11:00:44+00:00

I have an application that I’ve been working on and found a troubling difference

  • 0

I have an application that I’ve been working on and found a troubling difference tonight – and I thought I would document it here and see if anyone can replicate it and/or explain it. The query is made up, but demonstrates the problem:

select 
    '123' ~ '^\d+$' as result_1, 
    '123' ~ '^[0-9]+$' as result_2

I have a PostgreSQL v9.1 running on Windows 7 and when I run this query I get:

T, T

However, when I run the query on PostgreSQL v9.0 on a Ubuntu 10.04 I get:

F, T

So, it would appear that either PostgreSQL changed between v9.0 and v9.1 in its handling of “\d” or it has something to with differences between the libs that got installed between Windows and Ubuntu.

Either way, I think that folk should be aware that your check constraints, etc might not behave the same between the two (mine sure didn’t).

Note: unfortunately, I don’t have easy access to a Windows 7 box running 9.0 or I would test it there, also.

Can anyone explain this? If it’s well known, please forgive me. I didn’t see an answer when I googled for it. Obviously the safe thing to do is to just use [0-9] because it works in both locations. But, again, I would like to know why this is happening.

  • 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-29T11:00:45+00:00Added an answer on May 29, 2026 at 11:00 am

    You have an escaping problem. From the fine 9.1 manual on string quoting:

    If the configuration parameter standard_conforming_strings is off, then PostgreSQL recognizes backslash escapes in both regular and escape string constants. However, as of PostgreSQL 9.1, the default is on, meaning that backslash escapes are recognized only in escape string constants.

    So 9.1 sees '\d' the same way C does so it just looks like 'd'. In 9.1 you’d want to escape your backslash and use the E'' “escape” string notation to get past standard_conforming_strings:

    select 
        '123' ~ E'^\\d+$' as result_1, 
        '123' ~ '^[0-9]+$' as result_2
    

    Or you could try dollar quoting:

    select 
        '123' ~ $re$^\d+$$re$ as result_1, 
        '123' ~ '^[0-9]+$' as result_2
    

    but that’s pretty ugly and difficult to read with a regex (especially a regex that uses $ to anchor the end).

    Another option would be to use a POSIX character class instead of \d:

    select 
        '123' ~ '^[[:digit:]]+$' as result_1, 
        '123' ~ '^[0-9]+$' as result_2
    

    You should have been seeing warnings about '\d' in earlier versions as well, check your logs for things like this:

    WARNING:  nonstandard use of escape in a string literal
    LINE 1: select '\d';
                   ^
    HINT:  Use the escape string syntax for escapes, e.g., E'\r\n'.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have application that is up more than 3 days. I can see in
I have an application that I would like to embed inside our companies CMS.
I have application that produces files. I would like to connect those files with
I have an application that i am working on which needs actually a file
I have application that makes different queries with different results so the caching in
I have application that is connecting to the DB and if I enter incorrect
I have application that brings response via Ajax and creates 5-20 new jQuery click
I have an application that sends messages to an external web service. I build
I have an application that displays an image inside of a Windows Forms PictureBox
I have an application that reads a CSV file with piles of data rows.

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.