×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# How convert array elements to rows?

## How convert array elements to rows?

(OP)
I need to convert array elements to rows. Suppose that I have the array {5,77,39,19}. I need it as a table with the index in one column and the element in the other column:

#### CODE

index | element
------+--------
1 |       5
2 |      77
3 |      39
4 |      19
Which command does this?

### RE: How convert array elements to rows?

Do you need a data structure, a collection type or do you need a GUI-component to display your array?

The index is already part of your array: array[2]=39 if you don't insist in indexing your rows from 1...len, but can use 0...(len-1).

Else you add 1 to the index and get the row.

Or explain your problem in more detail.

don't visit my homepage: http://home.arcor.de/hirnstrom/bewerbung

### RE: How convert array elements to rows?

Like that

rski=> select i, (ARRAY[11,22,33])[i] from
generate_series(1,array_upper(ARRAY[11,22,33],1)) i;
i | array
---+-------
1 |    11
2 |    22
3 |    33
(3 rows)

If you know the dimension of a table you can replace array_upper with it.

### RE: How convert array elements to rows?

Sorry I forget the CODE tags. It looks better

#### CODE

rski=> select i, (ARRAY[11,22,33])[i] from
generate_series(1,array_upper(ARRAY[11,22,33],1)) i;
i | array
---+-------
1 |    11
2 |    22
3 |    33
(3 rows)

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!