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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:30:08+00:00 2026-05-27T16:30:08+00:00

As far as I can tell, my function properly resembles the samples I’ve seen.

  • 0

As far as I can tell, my function properly resembles the samples I’ve seen. Can someone clue me in as to how I get this to work?

create or replace function get_user_by_username(
    username varchar(250),
    online boolean
    ) returns setof record as $$
declare result record;
begin

    if online then 
        update users
        set last_activity = current_timestamp
        where user_name = username;
    end if;

    return query
    select
        user_id,
        user_name,
        last_activity,
        created,
        email,
        approved,
        last_lockout,
        last_login,
        last_password_changed,
        password_question,
        comment
    from
        users
    where
        user_name = username
    limit 1;

    return;
end;
$$ language plpgsql;
  • 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-05-27T16:30:08+00:00Added an answer on May 27, 2026 at 4:30 pm

    if you would like to create function returning setof record, you’ll need to define column types in your select statement

    More info

    Your query should look something like this:

    select * from get_user_by_username('Username', True) as 
      f(user_id integer, user_name varchar, last_activity, varchar, created date, email        archar, approved boolean, last_lockout timestamp, last_login timestamp, 
      last_password_changed timestamp, password_question varchar, comment varchar)
    

    (you will probably need to change the data types)

    I personaly prefer the types approach. it assures that if the function is edited, all the queries will return correct results. It might be a pain because every time you modify function’s arguments you’ll need to recreate/drop types aswell tho.

    Eg:

    CREATE TYPE return_type as 
    (user_id integer,
     user_name varchar,
     last_activity varchar,
     created timestamp,
     email varchar,
     approved boolean,
     last_lockout timestamp ,
     last_login timestamp,
     last_password_changed timestamp,
     password_question varchar,
     comment varchar);
    
    create or replace function get_user_by_username( username varchar(250), online 
    
    boolean) returns setof return_type as $$
    declare _rec return_type;
    begin
        if online then 
            update users
            set last_activity = current_timestamp
            where user_name = username;
        end if;
        for _rec in select
            user_id,
            user_name,
            last_activity,
            created,
            email,
            approved,
            last_lockout,
            last_login,
            last_password_changed,
            password_question,
            comment
          from
            users
          where
            user_name = username
          limit 1 
        loop
    
          return next _rec;
    
        end loop
    
    end;
    $$ language plpgsql;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As far as I can tell, this is isn't possible, so I'm really just
As far as I can tell, the best way to do this is do
As far as I can tell, this code is fine, and should display some
As far as I can tell this only is only broken in Internet Explorer.
I have some simple javascript that as far as i can tell should work
As far as I can tell this only affects IE 8. Using the following
Using mootools.js 1.3.2 and mootools-more.js As far as I can tell this is supposed
The script below works as far as i can tell: <script type=text/javascript language=javascript> $(document).ready(function()
As far as I can tell the iPhone multitouch framework sends the location of
As far as I can tell i'm doing everything by the book, but the

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.