Merging and returning arrays

Merging and returning arrays

I've two functions,

I've two functions,

CREATE OR REPLACE FUNCTION function_a(input varchar)
RETURNS setof integer AS $$
    SELECT somecolumn FROM some_things WHERE a_column = input;

CREATE OR REPLACE FUNCTION function_b(inputs varchar[]) RETURNS setof integer AS $$ DECLARE input varchar; result integer[]; BEGIN FOREACH input IN ARRAY inputs LOOP result := result || ARRAY[function_a(input)]; END LOOP; END; $$ LANGUAGE PLpgSQL;

I am running it like,

 SELECT function_b(ARRAY['a', 'b']);

The error,

ERROR:  query "SELECT result || ARRAY[function_a(input)]" returned more than one row
CONTEXT:  PL/pgSQL function function_b(character varying[]) line 7 at assignment

All I want to do is to run a function over an array. I've always used scripting languages like Ruby to do this kind of stuff instead of using SQL, but I'm trying to learn SQL as it is much faster to get results on the db console itself. I wish it wasn't so frustrating.


Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

PostgreSQL Connection Pooling: Part 4 – PgBouncer vs. Pgpool-II

Compare PgBouncer vs. Pgpool-II to see which PostgreSQL connection pooler offers the best features, and analyze throughput (TPS) in a performance benchmark.

PostgreSQL Tutorial - Learn PostgreSQL Database from Scratch

PostgreSQL Tutorial - Learn PostgreSQL Database from Scratch. Learn how to use PostgreSQL in this full course. PostgreSQL is a general purpose and object-relational database management system. It is the most advanced open source database system widely used to build back-end systems. What is a Database? What is SQL And Relational Database? What is PostreSQL AKA Postrgres? PostgreSQL Installation. How to Create Database.

Difference between postgresql.conf and

In this video, you'll see the difference between postgresql.conf and

8 Reasons To Learn PostgreSQL | Benefits of PostgreSQL Training

Learning PostgreSQL which is in demand now more than ever will certainly help you climb up the ladder of success. Explore the benefits of attending the PostgreSQL Training program.Now it plays a key role in many integrated data centers across the globe.

ScaleGrid DigitalOcean Support for MySQL, PostgreSQL and Redis™

ScaleGrid announces support for their fully managed hosting plans on DigitalOcean for MySQL, PostgreSQL and Redis™. See how developers can improve performance. MySQL and PostgreSQL are the top two open source relational databases in the world, and Redis is the top key-value database