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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:24:23+00:00 2026-06-12T22:24:23+00:00

I have the following sample data for a particular column symbol for sample table.

  • 0

I have the following sample data for a particular column symbol for sample table.

(Update:) The data is not in a regular pattern. Number may occur at any place in between characters.

symbol

COL4A1
COL4A3
COL8A2
COL2A1
COL12A1
COL12A1
COL16A1
COL19A1

I need to sort the this data on database level. I used the following query:

select symbol from sample order by symbol asc

Result is follows:

COL12A1
COL12A1
COL16A1
COL19A1
COL2A1
COL4A1
COL4A3
COL8A2

But I need to get the order in the following way:

COL2A1
COL4A1
COL4A3
COL8A2
COL12A1
COL12A1
COL16A1
COL19A1
  • 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-12T22:24:24+00:00Added an answer on June 12, 2026 at 10:24 pm

    PostgreSQL doesn’t offer a number-aware collation that can do “humanized” sorts like “1A, 2A, 3A, … 10A, 11A, …”. It relies on the operating system for collation, and I’m not aware of any OS that exposes such a collation to applications.

    To do this, you need to split the text according to a pattern and order by the pattern parts, probably using regexp_matches.

    CREATE TABLE Table1 ("symbol" text);
    INSERT INTO Table1 ("symbol") VALUES
        ('COL4A1'),('COL4A3'),('COL8A2'),('COL2A1'),
        ('COL12A1'),('COL12A1'),('COL16A1'),('COL19A1');
    
    WITH matched(symbol, symbol_parts) AS (
      SELECT symbol, regexp_matches(symbol, '(\D*)(\d+)(\D+)(\d+)')
      FROM Table1
    )
    SELECT symbol 
    FROM matched
    ORDER BY symbol_parts[1], symbol_parts[2]::integer,
             symbol_parts[3], symbol_parts[4]::integer;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following sample data: Id Name Quantity 1 Red 1 2 Red
I have the following sample of data to insert into tables(from parent to child,
1I have the following two tables (sample data) and need to be able to
I have the following String Sample however in some occurences there may be one
Possible Duplicate: sql query to sum the data I have following table structure TradeId
I have the following sample code and noticed that if I attempt to use
I have the following sample code which doesn't seem to want to run. import
I have the following sample dataset (below and/or as CSVs here: http://goo.gl/wK57T ) which
I have the following test sample: <Window x:Class=WpfScrollTest.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=Window1 Height=200 Width=200> <Border>
I have the following code sample that im trying to wrap my head around

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.