PostgreSQL – Splitting Metadata Efficiently

postgresql

I have metadata in a postgresql table that I need to split. So far I have been attempting to use

Select col_name from "tbl_name" split_part('QGC|WGPLNW|IR|BBC|FCPC|WGPLNW|ARME|QPC', ", 1 | 2 | 3 | etc...); 

Out of a table formatted like so:

QGC 10''
QGC 10''
QGC 10''
QGC 10''
QGC 12''
QGC 12''
QGC 12''
QGC 12''
QGC 12''
QGC 10''

I need only to extract the integers and would like to preserve the acronyms if possible. I have attempted to use the split substring with regex function but haven't found much success, although this is primarily due to my lack of understanding of how to pass substrings inside of queries when dealing with a table. If someone could explain the appropriate syntax in order to perform this task they would help me greatly. Thanks in advance.

Thanks Martin, You are right – I placed this in the wrong section, thanks for your input. Also, you are correct in assuming that the quotes are holdovers from the database and I have corrected them to more accurately represent the data. How would I go about having the topic moved as not to darken the door of gis.stackexchange?

Best Answer

After looking at split_part() from PostgreSQL String Functions, and assuming that column is the name of the "compound attribute" that is of the form "acronym codenum", then I'd say you should try something like this

SELECT 
  split_part (column, ' ', 1) AS acronym,
  split_part (column, ' ', 2) AS codenum
FROM table