Solved

How to grab this with SQL in PostgreSQL

Posted on 2015-02-21
4
117 Views
Last Modified: 2015-03-12
Hi,

here is sqlfidlle

http://sqlfiddle.com/#!11/c0c1c

I would like to get bellow result out of that...

fist  |  second
100  | 200
101  | 201
102  | 202
103  | 203
104  | 204
105  | 205

regards
0
Comment
Question by:hi4ppl
  • 2
4 Comments
 
LVL 13

Accepted Solution

by:
Mark Bullock earned 500 total points
ID: 40623135
Here's a basic example. You can make it more flexible by replacing 3 with the position of the next comma.
select position('{name,' in thatfield) 
, substring( thatfield from 6+position('{name,' in thatfield) for 3) as first
, substring( thatfield from 10+position('{name,' in thatfield) for 3) as second
from table1

Open in new window

0
 
LVL 22

Expert Comment

by:earth man2
ID: 40623169
I presume you want to work with ARRAY type columns ?
Something like the following may guide you in the right direction ..

CREATE TABLE Table1
      (ThatField text[][])
;
      
INSERT INTO Table1
      (ThatField)
VALUES ('{{secondname,200,null},{name,103,203}}'),
      ('{{name,105,205}}')
;

select thatfield[1][2] as col1,thatfield[1][3] as col2 from table1
where thatfield[1][3] is not null
union all
select thatfield[2][2] as col1,thatfield[2][3] as col2 from table1
where thatfield[1][3] is null
;
0
 
LVL 1

Author Comment

by:hi4ppl
ID: 40637911
Hi,

thanks Mark, can you please explain this to me like specially the 6+position part

thanks
0
 
LVL 13

Expert Comment

by:Mark Bullock
ID: 40638555
The length of '{name,' is 6 characters.
6+ is to get the position of the first character following '{name,'.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Best database to use for Maps is PostgreSQL. This is an open source database. Comes as a package with most Linux OS. For more info visit the following site: http://www.postgresql.org/ (http://www.postgresql.org/) This requires some add-o…
Many developers have database experience, but are new to PostgreSQL. It has some truly inspiring capabilities. I have several years' experience with Microsoft's SQL Server. When I began working with MySQL, I wanted a quick-reference to MySQL (htt…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question