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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:55:01+00:00 2026-06-17T02:55:01+00:00

I need to compare 2 strings that contains number and possibly text. for example

  • 0

I need to compare 2 strings that contains number and possibly text. for example I have this table:

id | label 1  |  label 2 | 
1  |  12/H    |     1    |
2  |   4/A    |    41/D  |
3  |  13/A    |     3/F  |
4  |   8/A    |     8/B  |
..

I need to determine the direction so that if Label 1 < Label2 then Direction is W (with) else it is A (against). So I have to build a view that presents data this way:

id | Direction  
1  |     A    |   
2  |     W    |
3  |     A    |
4  |     W    |
..

I’m using postgres 9.2.

  • 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-06-17T02:55:02+00:00Added an answer on June 17, 2026 at 2:55 am
    WITH x AS (
       SELECT id
             ,split_part(label1, '/', 1)::int AS l1_nr
             ,split_part(label1, '/', 2)      AS l1_txt
             ,split_part(label2, '/', 1)::int AS l2_nr
             ,split_part(label2, '/', 2)      AS l2_txt
       FROM t
       )
    SELECT id
          ,CASE WHEN (l1_nr, l1_txt) < (l2_nr, l2_txt)
           THEN 'W' ELSE 'A' END AS direction
    FROM   x;
    

    I split the two parts with split_part() and check with an ad-hoc row type to check which label is bigger.

    The cases where both labels are equal or where either one is NULL have not been defined.

    The CTE is not necessary, it’s just to make it easier to read.

    -> sqlfiddle

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

Sidebar

Related Questions

I have random data (names) in strings that I need to compare. Data (names)
I have two documents with a simple schema that I need to compare: current
I need to read in a file that contains 2 sentences to compare and
I have a file that contains the output of a file compare thats written
So I have two files, one that contains my text, and another which I
In my code I need to compare string letters but my problem is that
I get two strings formated like (Brazilian Format): DD/MM/YYYY, I need to compare both.
I'm developping a web app and I need encrypt strings in javascript to compare
I have an if statement, and I need to compare a single string with
I'm using two string vectors to store two text files. I need to compare

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.