There is a table of the form:

col1 | col2 | col3 ------+--------+-------------- text11| text21 | 1234567890123 text21| text22 | 3210987654321 text31| text32 | 2342342554455 

It is necessary to make a selection from the table table, containing the values ​​of the columns col1 and col2 completely, and from the values ​​of col3 take only the first 10 digits.

The problem arises with col3 , I can not figure out how to make a sample. There are thoughts to use regular expressions. but I don’t know how to regexp ^\d{1,10} to the request

  • 2
    Use substring () - MaxU
  • Fits, but how to use the value from the table instead of string? (substring (string from pattern)) Now the query looks like this: SELECT col1, col2, substring ('col3' from '^ \ d {1,10}') FROM TABLE; - cavabanga1
  • one
    SELECT col1,col2,substring(col3 from '^\d{1,10}') FROM TABLE ? - MaxU

1 answer 1

I figured it out myself:

 SELECT col1,col2, substring(cast(col3 as text), 1 , 10) FROM table;