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 8755695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:54:17+00:00 2026-06-13T13:54:17+00:00

Following up from my previous question: Pixel values of raster records to be inserted

  • 0

Following up from my previous question:

Pixel values of raster records to be inserted in the table as columns

Imagine my query result has 5300 row as results like:

+-------+ 
|value  |
+-------+
| 15624 |
| 15899 |
| 56267 |
| 85955 |
+-------+

I want them to be in a table and first 53 rows in val1 column, second 53 rows in val2 column and so on. In the end I will have 100 new columns in my table. Is this possible? and if so, how can I achieve it?

  • 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-13T13:54:18+00:00Added an answer on June 13, 2026 at 1:54 pm

    Here’s a possibly somewhat saner approach using multi-dimensional arrays.

    Please never, ever, ever, ever use the following query:

    CREATE EXTENSION tablefunc;
    
    SELECT * FROM crosstab(
      'SELECT ''row1''::text, width_bucket(x, 1, 53001, 100), array_agg(x order by x)::integer[] from generate_series(1,53000) x GROUP BY 2'
    ) ct(
     rowname text,
        col1 integer[], col2 integer[], col3 integer[], col4 integer[], col5
        integer[], col6 integer[], col7 integer[], col8 integer[], col9 integer[],
        col10 integer[], col11 integer[], col12 integer[], col13 integer[], col14
        integer[], col15 integer[], col16 integer[], col17 integer[], col18 integer[],
        col19 integer[], col20 integer[], col21 integer[], col22 integer[], col23
        integer[], col24 integer[], col25 integer[], col26 integer[], col27 integer[],
        col28 integer[], col29 integer[], col30 integer[], col31 integer[], col32
        integer[], col33 integer[], col34 integer[], col35 integer[], col36 integer[],
        col37 integer[], col38 integer[], col39 integer[], col40 integer[], col41
        integer[], col42 integer[], col43 integer[], col44 integer[], col45 integer[],
        col46 integer[], col47 integer[], col48 integer[], col49 integer[], col50
        integer[], col51 integer[], col52 integer[], col53 integer[], col54 integer[],
        col55 integer[], col56 integer[], col57 integer[], col58 integer[], col59
        integer[], col60 integer[], col61 integer[], col62 integer[], col63 integer[],
        col64 integer[], col65 integer[], col66 integer[], col67 integer[], col68
        integer[], col69 integer[], col70 integer[], col71 integer[], col72 integer[],
        col73 integer[], col74 integer[], col75 integer[], col76 integer[], col77
        integer[], col78 integer[], col79 integer[], col80 integer[], col81 integer[],
        col82 integer[], col83 integer[], col84 integer[], col85 integer[], col86
        integer[], col87 integer[], col88 integer[], col89 integer[], col90 integer[],
        col91 integer[], col92 integer[], col93 integer[], col94 integer[], col95
        integer[], col96 integer[], col97 integer[], col98 integer[], col99 integer[],
        col100 integer[]
    );
    

    The correct way to solve this problem is almost certainly in your application. SQL is good at many things. This isn’t one of them, especially in PostgreSQL with its very limited pivot support. In any database this would be a crazy thing to do.

    As far as I’m concerned, if I have to use a query just to generate the column-list, that’s a sign the system is being forced to do something it isn’t well suited for:

    select string_agg('col'||n||' integer[]',', ') FROM generate_series(1,100) n;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following on from this previous question: Linq query for EF 4.1 data with nested
Hi I have the following query from a previous question and need to convert
Following on from my previous Dynamics CRM question ( Show popup/alert if account has
Following on from my previous question: Simple inner join in linq How would I
Following up from my previous question , why is CShell so different from C?
Following on from a previous question, for some reason when I use the following
Following on from a previous question relating to heap usage restrictions , I'm looking
Following on from a previous question , I am creating a symbolic link on
Okay, this is following on from my previous question reguarding performing a simple ajax
This problem follows on from a previous question . When I run the following

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.