3

I had some help on here and got the following code:

-- Setup Solrid Function
CREATE OR REPLACE FUNCTION solrid(IN local_id INTEGER, OUT result TEXT) AS $$
DECLARE
  database_id TEXT := 'A';
BEGIN
  result := database_id || local_id::TEXT;
END;
$$ LANGUAGE PLPGSQL;

However when I run it in sqlfiddle it says:

Schema Creation Failed: ERROR: unterminated dollar-quoted string at or near "$$ DECLARE database_id TEXT := 'A'":

This error may seem pretty self explanatory but I can't figure out the way to fix it. Would anyone mind shedding some light on this please?

Jimmy
  • 12,087
  • 28
  • 102
  • 192
  • Interesting, works just fine on my local db (postgresql 9.1) – Tomas Greif Feb 05 '13 at 15:45
  • Maybe its a bug with sqlfiddle? I've tried it with a few different versions and it throws up the same error each time. – Jimmy Feb 05 '13 at 15:54
  • Start by providing the version number you use and how you execute the code. – Erwin Brandstetter Feb 05 '13 at 16:21
  • 5
    Sorry Jimmy, this is a confusing part of SQL Fiddle. The problem is that your semi-colon within your function body is breaking my default parsing mechanism. If you change your "query terminator" to something other than a semi-colon (the default) your function will work fine: http://sqlfiddle.com/#!1/ede11 – Jake Feasel Feb 07 '13 at 17:06

1 Answers1

0

There is absolutely nothing wrong with this function, it is 100 % legit. I tested with 8.4 and 9.1 in my installation.

There must be some kind of misunderstanding. This cannot be exactly the same code that triggers the error message.

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
  • If you uncomment the function at the bottom and build schema it gives the error. I think based on what you say it is a bug with the website: http://sqlfiddle.com/#!11/6810d – Jimmy Feb 05 '13 at 16:24
  • 5
    @ErwinBrandstetter Actually, SQL Fiddle does support functions. You just have to change the "query terminator" to something other than a semi-colon. http://sqlfiddle.com/#!1/ede11 – Jake Feasel Feb 07 '13 at 17:07
  • @JakeFeasel: That's awesome! I didn't know that. Deleted my incorrect comment. Would be great, of course, if the query terminator thingy could be fixed somehow, too. – Erwin Brandstetter Feb 07 '13 at 17:14
  • @ErwinBrandstetter yes, it's a feature that I've long thought about how to improve its visibility. Clearly a UX fail. I have some ideas about how to improve it that I'm hoping to get around to trying out soon. – Jake Feasel Feb 07 '13 at 18:19