Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8847005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:07:11+00:00 2026-06-14T12:07:11+00:00

I have a table that contains an array of ints (we’ll call it lineTable).

  • 0

I have a table that contains an array of ints (we’ll call it lineTable). That array of int’s represents an array of unique id’s in another table (pointTable). The point table in turn contains 3 columns (id, x, y).

I want to be able to convert each one of those ints in the lineTable.points to an array of of array of ints.

lineTable              pointTable
| id | points |        | id | x | y |
| int| int[]  |        | int|int|int|

lineTable
| 1 | {1, 2, 3, 4, 5} |
| 2 | {4, 7, 5, 2, 3} |
| 3 | {8, 1}          |
etc

pointTable
| 1 | 1 | 0 |
| 2 | 2 | 1 |
| 3 | 5 | 6 |
| 4 | 7 | 0 |
| 5 | 2 | 4 |
| 6 | 5 | 2 |
| 7 | 4 | 4 |
| 8 | 5 | 9 |

So what I want the eventual output to be would be

lineValues
| {{1, 0}, {2, 1}, {5, 6}, {7, 0}, {2, 4}} |
| {{7, 0}, {4, 4}, {2, 4}, {2, 1}, {5, 6}} |
| {{5, 9}, {1, 0}}                         |

Note: The ID’s can be any number and are not in a sequential pattern (it may go 1, 2, 5, 10, 11, 18)

I am using Postgre 9.2.

Thank You for any assistance. Let me know if you need/want any other information.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:07:12+00:00Added an answer on June 14, 2026 at 12:07 pm

    This is pretty straight forward if you wanted to use a composite type, such as the native Point type, in your array. Something like this:

    select dt.id, array_agg(point(p.x, p.y))
    from pointtable p
    join (
        select id, unnest(points) as p
        from linetable
    ) as dt on p.id = dt.p
    group by dt.id
    order by dt.id;
    

    would give you this sort of output:

     id |                 array_agg                 
    ----+-------------------------------------------
      1 | {"(1,0)","(2,1)","(5,6)","(7,0)","(2,4)"}
      2 | {"(2,4)","(4,4)","(7,0)","(5,6)","(2,1)"}
      3 | {"(1,0)","(5,9)"}
    

    Then you could work with the points.

    If you really want a two dimensional array then you can create your own aggregate function:

    create aggregate
    array_cat_agg(int[])
    (sfunc = array_cat, stype = int[], initcond = '{}');
    

    and then:

    select dt.id, array_cat_agg(array[[p.x, p.y]])
    from pointtable p
    join (
        select id, unnest(points) as p
        from linetable
    ) as dt on p.id = dt.p
    group by dt.id
    order by dt.id;
    

    to get this:

     id |          array_cat_agg          
    ----+---------------------------------
      1 | {{1,0},{2,1},{5,6},{7,0},{2,4}}
      2 | {{2,1},{5,6},{7,0},{2,4},{4,4}}
      3 | {{1,0},{5,9}}
    

    Note the array[[...]] trickery, you need that to make sure you get the right version of array_cat, if you just array[...] then you’ll end up with a flattened array and that will make you sad. You can’t just use array_agg here as there’s no such thing as an array-of-arrays and array_agg(array[p.x, p.y]) wants to create an array-of-arrays. Hence the custom aggregate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that contains the following columns: ID int, DISTANCE float, EVENT
I have a table that contains a record of prioritys that links to another
I have a table that contains multiple dropdown menus for a list of profile
I have a table that contains all the data about users . Users can
I have a table that contains common entries in two columns. For Example: Column1
I have a table that contains the stock. It's legacy database and the stock
I have a table that contains an Id column as a primary key. There
I have a table that contains userids and their score. eg. userid rating 123
I have a table that contains intervals: CREATE TABLE tbl ( user_id: INTEGER, start:
I have a table that contains id, created, user_id. I'm wondering if there is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.