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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:02:11+00:00 2026-06-01T16:02:11+00:00

I am trying to create a function that does this: drop table t_rv_openitem; select

  • 0

I am trying to create a function that does this:

drop table t_rv_openitem;
select * into t_rv_openitem from rv_openitem;
select * from t_rv_openitem;

I am confused sometimes when it comes to functions in PostgreSQL and get this error:

An error has occurred:

ERROR: syntax error at or near “DROP” LINE 3: DROP TABLE
t_rv_openitem;

I know this seems like a simple task but I am pulling my hair out trying to figure this out.

Here is the full function create statement:

CREATE OR REPLACE FUNCTION adempiere.update_t_rv_openitem()
  RETURNS rv_openitem AS
$BODY$

Drop table t_rv_openitem;
select * into t_rv_openitem from rv_openitem;
select * From t_rv_openitem;

$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION adempiere.update_t_rv_openitem() OWNER TO adempiere; 
  • 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-01T16:02:13+00:00Added an answer on June 1, 2026 at 4:02 pm

    Just add BEGIN and END

    CREATE OR REPLACE FUNCTION adempiere.update_t_rv_openitem()
      RETURNS rv_openitem AS
    $BODY$
    
    BEGIN -- ADD THIS
    
    Drop table t_rv_openitem;
    select * into t_rv_openitem from rv_openitem;
    select * From t_rv_openitem;
    
    END; -- AND THIS
    
    $BODY$
      LANGUAGE plpgsql VOLATILE
      COST 100;
    ALTER FUNCTION adempiere.update_t_rv_openitem() OWNER TO adempiere; 
    

    You don’t need BEGIN and END block if you are using LANGUAGE sql, you need those though if you are using LANGUAGE plpgsql

    UPDATE

    Regarding ERROR: syntax error at "t_rv_openitem" DETAIL: Expected record variable.... There’s no syntax error on your code, you just need to change this:

    select * into t_rv_openitem from rv_openitem;
    

    To this:

    create table t_rv_openitem as
    select * from rv_openitem;
    

    The table creation using SELECT * INTO tablehere FROM tableSource works only if you are using it outside of PLPGSQL; when that code struct is inside PLPGSQL, the semantic will be different, it means:

    SELECT * INTO declaredVariableHere FROM tableSource;
    

    To make table creation work on both stand-alone statement and inside PLPGSQL, just use:

    CREATE TABLE AS SELECT * FROM tableSourceHere;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a function in package that returns a table. I hope
I'm trying to create a function in Groovy that does the following: Accepts 2
I am trying to create a function that deletes a user from Constant Contact.
I'm trying to create a function that searches up a WebControl's parent-child relationship (basically
I am trying to create a function that will block access to some of
I'm trying to create a function that would dynamically allocate an array, sets the
I am trying to create a function that given a divid, and a list
I'm trying to create a function that will simply allow me to pass an
I am trying to create a function that sends 100 call per second, and
I’m trying to learn Haskell and I was trying to create a function that

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.