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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:26:22+00:00 2026-06-12T09:26:22+00:00

I have a plpgsql function that takes an integer[] as input. The whole setup

  • 0

I have a plpgsql function that takes an integer[] as input.

The whole setup can be found in this question:
Passing a record as function argument PL/pgSQL

Short version:
I have an n to m relationship from books to authors with a link table called books_author. I now have a function that looks like this:

    create function f_insert_books(title varchar, isbn varchar, publisher varchar,  
      author_id integer[]) returns void as $$
      begin
      --insert book
      --insert link to authors into the books_author table
      end;
    $$ language plpgsql;

I now want to add the number_of_authors to the book. Is there an easy way to determine the size of the author_id array or would you recomment passing the “number_of_authors int” as an input parameter?

I found this suggestion, but I am a bit worried about performance in this approach. So maybe there’s something easier/faster.
http://archives.postgresql.org/pgsql-sql/2000-06/msg00169.php

Thank you very much for your help.

  • 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-12T09:26:23+00:00Added an answer on June 12, 2026 at 9:26 am

    Use array_length:

    SELECT array_length( ARRAY[1,2,3], 1 );
    

    The 2nd parameter is the dimension you’re interested in. Most arrays are 1-dimensional, so 1 is the right value in most cases.

    If you’re in fact looking for the length of all the strings in a text array, use array_to_string with length:

    SELECT length(array_to_string( ARRAY['a','bb','ccc'], '' ));                                                                                                         
    

    BTW, the article you linked to is 12 years old and appears completely obsolete.

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

Sidebar

Related Questions

If I have a function in PL/pgSQL that takes in a timestamp, what is
I have this upsert function that allows me to modify the fill_rate column of
I have a function that is used as an INSERT trigger. This function deletes
I have a plpgsql function that executes a query, but when i put an
I have the following plpgsql function that does work great on pg 8.3 and
I have a function in PostgreSQL (PLPGSQL) that returns an array containing two elements.
I have this Trigger in Postgresql that I can't just get to work (does
I have a PL/pgSQL function which requires one input parameter which is the primary
I have a sql function that does a simple sql select statement: CREATE OR
I have this function to be created, but the variable view_size is being treated

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.