Solved

How to grab this with SQL in PostgreSQL

Posted on 2015-02-21
4
110 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now