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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:38:36+00:00 2026-06-18T06:38:36+00:00

How to select array_agg(ARRAY[f1_date,ARRAY[f2_int,f3_decimal]]) ? There is an error about combining date and integer

  • 0

How to select array_agg(ARRAY[f1_date,ARRAY[f2_int,f3_decimal]])? There is an error about combining date and integer in ARRAY.

upd: added picture explaining where and how I plan to use array. The issue is db size. After transforming 3 colunms to multidimensional array I can save plenty of space. It will be 4M rows instead of 200M. Each row will have array with maximum 500 elements inside.

enter image description here

  • 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-18T06:38:37+00:00Added an answer on June 18, 2026 at 6:38 am

    Arrays in Postgres share the same base element across all dimensions.

    Array of anonymous records

    You can build an array of anonymous records (as base type):

    SELECT array_agg((i,d))
    FROM  (
       VALUES
         (1::int, 2.3::decimal)
        ,(2, 3.4)
        ,(3, 4.5)
       ) x(i, d);
    

    This is rather unwieldy though, as you cannot access subfields of anonymous records by name (names do not exist!). May be more practical to operate with well know types ..

    Composite type as base type

    Create a composite type and use it as base type for your array.

    CREATE TYPE int_dec AS (i int, d decimal);
    
    SELECT '(1, 2.3)'::int_dec AS id_base
          ,'{"(1, 2.3)","(2, 3.4)","(3, 4.5)"}'::int_dec[] AS id_arr
    
    -- Build an array from composite base type
    SELECT array_agg(a)
    FROM (
        VALUES
          ('(1, 2.3)'::int_dec)
         ,('(2, 3.4)'::int_dec)
         ,('(3, 4.5)'::int_dec)
        ) x(a);
    
    -- Build an array from composite base type
    SELECT array_agg((i,d)) AS anonymous_arr
          ,array_agg((i,d)::int_dec) AS id_arr
    FROM  (
       VALUES
         (1::int, 2.3::decimal)
        ,(2, 3.4)
        ,(3, 4.5)
       ) x(i, d);
    

    Table as base type

    Any table can serve as composite type.

    db=# CREATE TEMP TABLE int_dec (i int, d decimal);
    CREATE TABLE
    db=# INSERT INTO int_dec VALUES (1, 2.3), (2, 3.4), (3, 4.5);
    INSERT 0 3
    db=# SELECT array_agg(id) FROM int_dec id;
                array_agg
    ---------------------------------
     {"(1,2.3)","(2,3.4)","(3,4.5)"}
    

    Text as common ground

    The alternative is to cast all values to text since every data type can be cast to text and back in PostgreSQL and build a multi-dimensional array.

    For that you may be interested in aggregating multi-dimensional arrays. Consider the answer under this related question:
    Selecting data into a Postgres array

    In my experience there is often a better solution than to build complex arrays, though.

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

Sidebar

Related Questions

There is a drop down using select <%= select(array, folder, @rows.keys, {}, :onchange =>?
When using array_agg or array_string, the array returns empty above a certain size. SELECT
Is it possible to make one big array from a query like: select array_append(ARRAY[0],
Given an Array A of n subArrays Sn, how can I select the Array
I have the following example code: $dataProvider = new CActiveDataProvider('firstTable', array('criteria' => array( 'select'
I have array of select tag. <select id='uniqueID' name=status> <option value=1>Present</option> <option value=2>Absent</option> </select>
I have used PHP array for HTML select, then I put my codes in
Ruby has a select method that takes an array and returns a subarray consisting
I am filtering an array in ruby and using a .select block to do
I am trying to select an object from this array and print all of

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.