Solved

How to grab this with SQL in PostgreSQL

Posted on 2015-02-21
4
126 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 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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