?
Solved

How to grab this with SQL in PostgreSQL

Posted on 2015-02-21
4
Medium Priority
?
138 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
Mark Bullock earned 2000 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 14

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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

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…
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month11 days, 13 hours left to enroll

752 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