6

Is there any difference between:

CREATE FUNCTION func() RETURNS integer
    LANGUAGE plpgsql AS $$
    declare
    begin
      -- do something
    end
$$;

and

CREATE FUNCTION func() RETURNS INTEGER AS $$
    declare
    begin
      -- do something
    end
$$ LANGUAGE plpgsql;

Does LANGUAGE plpgsql basically just have to be outside the scope of the $$ usage?

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
Ben
  • 129
  • 1
  • 1
  • 11

1 Answers1

6

No difference whatsoever.
The function body is a string literal. The $$ are just dollar-quotes and could be single quotes, too (but better use dollar quotes!):

CREATE FUNCTION is a declarative SQL-DDL command, and the order of keywords is pretty free, as per definition in the manual. (Key words within the curly braces in the command definition can be arranged freely, but not the rest).

I eventually settled on always putting the language declaration on top with the rest of the function header, before the function body. Makes more sense.

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228