Re: quoting and EXECUTE in plpgsql function - Mailing list pgsql-general

From Doug McNaught
Subject Re: quoting and EXECUTE in plpgsql function
Date
Msg-id m3wunu2h8g.fsf@varsoon.wireboard.com
Whole thread Raw
In response to quoting and EXECUTE in plpgsql function  ("Matthew Nuzum" <cobalt@bearfruit.org>)
List pgsql-general
"Matthew Nuzum" <cobalt@bearfruit.org> writes:

> Hello, I'm writing my first large plpgsql function and I'm having a
> little difficulty.
>
> First, let me say that I'm editing my function through phpPgAdmin, and I
> believe that it requires you to escape all single quotes when entering
> functions.  I'm not sure if that is also true when creating a function
> using the command line tools.

Yes.

> EXECUTE '' INSERT INTO raw_data '' ||

Any reason you're using EXECUTE here?  EXECUTE is really only needed
when the table or column names need to be determined at runtime.  Your
query looks quite normal, so you don't need to use EXECUTE.  As a
bonus, the query will get compiled and the plan saved so you won't be
calling the planner for every row you insert.

Second, I don't think you need quote_ident, especially if you're not
using EXECUTE.

You should just be able to do something like:

INSERT INTO foo_table (bar, baz, quux) VALUES (bar, baz, quux);

(assuming bar, baz and quux are aliased in your declaration section.

Give that a try.

-Doug

pgsql-general by date:

Previous
From: "Matthew Nuzum"
Date:
Subject: quoting and EXECUTE in plpgsql function
Next
From: Tom Lane
Date:
Subject: Re: quoting and EXECUTE in plpgsql function