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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:01:03+00:00 2026-06-09T19:01:03+00:00

I have the following script that I want output to the screen from. CREATE

  • 0

I have the following script that I want output to the screen from.

CREATE OR REPLACE FUNCTION randomnametest() RETURNS integer AS $$
DECLARE
    rec RECORD;
BEGIN
    FOR rec IN SELECT * FROM my_table LOOP
        SELECT levenshtein('mystring',lower('rec.Name')) ORDER BY levenshtein;
    END LOOP;

    RETURN 1;
END;
$$ LANGUAGE plpgsql;

I want to get the output of the levenshein() function in a table along with the rec.Name. How would I do that? Also, it is giving me an error about the line where I call levenshtein(), saying that I should use perform instead.

  • 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-09T19:01:05+00:00Added an answer on June 9, 2026 at 7:01 pm

    If you want the output from a plpgsql function like the title says:

    CREATE OR REPLACE FUNCTION randomnametest(_mystring text)
      RETURNS TABLE (l_dist int, name text) AS
    $BODY$
    BEGIN
        RETURN QUERY
        SELECT levenshtein(_mystring, lower(t.name)), t.name
        FROM   my_table t
        ORDER  BY 1;
    END;
    $$ LANGUAGE plpgsql;
    
    • Declare the table with RETURNS TABLE.
    • Use RETURN QUERY to return records from the function.
    • Avoid naming conflicts between column names and OUT parameters (from the RETURNS TABLE clause) by table-qualifying column names in queries. OUT parameters are visible everywhere in the function body.
    • I made the string to compare to a parameter to the function to make this more useful.

    There are other ways, but this is the most effective for the task. You need PostgreSQL 8.4 or later.

    For a one-time use I would consider to just use a plain query (= function body without the RETURN QUERY above).

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

Sidebar

Related Questions

I have the following shell script that echos output to the log and errors
I have the following script that I want to insert into a table, but
I have a shell script that I want to call from a python program,
I have following script that executes all the .reg files in the current directory.
I have the following script that works well in Firefox and Chrome (not sure
I have the following script that changes my image on a timer: var da
I have the following script that successfully retrieves the current track and updates my
I have the following script that runs when a user clicks a link that
I have the following simple python test script that uses Suds to call a
I have the following situation. I have a PHP script that imports a CSV

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.