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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:00:07+00:00 2026-06-13T03:00:07+00:00

In a plpgsql function, I have a variable of type record: my_rec RECORD; This

  • 0

In a plpgsql function, I have a variable of type record:

my_rec RECORD;

This record contains a row from an arbitrary table, so I do not know the columns before it is executed.
However, I do have the name of at least one of the columns available as a varchar.

The question is: How do I retrieve the value for a given column from my_rec?

  • 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-13T03:00:09+00:00Added an answer on June 13, 2026 at 3:00 am

    Use hstore to work with records with dynamic columns in PL/PgSQL functions:

    CREATE EXTENSION hstore;
    
    CREATE OR REPLACE FUNCTION test_fn(col_name text) RETURNS text AS $$
    DECLARE 
      input_row record;
      col_value text;
    BEGIN
      SELECT INTO input_row 
        * 
      FROM ( VALUES ('a','b','c',1) ) AS dummyrow(col1,col2,col3,intcol);
    
      SELECT INTO col_value
        hstore(input_row) -> col_name;
    
      RETURN col_value;
    END;
    $$ LANGUAGE 'plpgsql';
    

    hstore is an extension, but it’s an extension that’s been bundled with PostgreSQL since 8.3 and has been installable using CREATE EXTENSION since 9.1. The record-to-hstore conversion has been supported since something like 8.4 or 9.0.

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

Sidebar

Related Questions

I have this function to be created, but the variable view_size is being treated
i have this simple plpgsql function: CREATE FUNCTION update_times () RETURNS trigger AS '
I have this function in PostgreSQL, but I don't know how to return the
I have this recommendations table: Table public.recommendations Column | Type | Modifiers -----------------------+-----------------------------+-------------------------------------------------------------- id
I have two tables like this: CREATE TABLE table1_lang ( id serial NOT NULL,
Is it possible for a PostgreSQL plpgsql function to not return anything? I've created
I have a function that is used as an INSERT trigger. This function deletes
I have this upsert function that allows me to modify the fill_rate column of
I have PostgreSQL 8.4 with 3 pairs of tables like this: CREATE TABLE filedata_temp
I'm trying to fetch to values from a plpgsql function with 2 OUT paramenters

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.