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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:22:35+00:00 2026-05-25T15:22:35+00:00

Working on postgres SQL. I have a table with a column that contains values

  • 0

Working on postgres SQL.

I have a table with a column that contains values of the following format:

Set1/Set2/Set3/…

Seti can be a set of values for each i. They are delimited by ‘/’.

I would like to show distinct entries of the form set1/set2 and that is – I would like to trim or truncate the rest of the string in those entries.
That is, I want all distinct options for:

Set1/Set2

A regular expression would work great: I want a substring of the pattern: .*/.*/

to be displayed without the rest of it.

I got as far as:

select distinct column_name from table_name

but I have no idea how to make the trimming itself.

Tried looking in w3schools and other sites as well as searching SQL trim / SQL truncate in google but didn’t find what I’m looking for.

Thanks in advance.

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

    If they really are that regular you could use substring; for example:

    => select substring('Set1/Set2/Set3/' from 1 for 9);
     substring 
    -----------
     Set1/Set2
    (1 row)
    

    There is also a version of substring that understands POSIX regular expressions if you need a little more flexibility.

    The PostgreSQL online documentation is quite good BTW:

    http://www.postgresql.org/docs/current/static/index.html

    and it even has a usable index and sensible navigation.


    If you want to use .*/.* then you’d want something like substring(s from '[^/]+/[^/]+'), for example:

    => select substring('where/is/pancakes/house?' from '[^/]+/[^/]+');
     substring 
    -----------
     where/is
    (1 row)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help me to write the following sql. I have a table like this,
I have a table I'm working on that has around 3 million tuples. It
I have a migration that runs an SQL script to create a new Postgres
Could you tell my why the following isnt working in postgres sql?: See updated
I am thinking of working on a Rails application that uses PostgreSQL. I have
I have a postgres table like this: CREATE SEQUENCE seq; CREATE TABLE tbl (id
I have a table that maintains rows of products that are for sale (
I have a sql function that does a simple sql select statement: CREATE OR
I have SQL query, which is working nice on Oracle and MSSQL. Now I'm
I have been working with Microsoft SQL Server since 6.5 along with other database

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.