Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2005
    Posts
    18

    Unanswered: ERROR: syntax error at or near "$";

    Full message: Error: ERROR: syntax error at or near "$";
    Error while executing the query (State:42601, Native Code: 7)

    Code:
    CREATE FUNCTION somefunc() RETURNS integer AS $$
    DECLARE
        quantity integer := 30;
    BEGIN
        RAISE NOTICE 'Quantity here is %', quantity;  -- Quantity here is 30
        quantity := 50;
        --
        -- Create a subblock
        --
        DECLARE
            quantity integer := 80;
        BEGIN
            RAISE NOTICE 'Quantity here is %', quantity;  -- Quantity here is 80
        END;
    
        RAISE NOTICE 'Quantity here is %', quantity;  -- Quantity here is 50
    
        RETURN quantity;
    END;
    $$ LANGUAGE plpgsql;
    I dont understand why its error.
    Even simple script cannot be run.
    I just installed PostgreSQL today then when I try to create a stored procedure..the error messages was appeared even the syntax was corrent.. (i think because its from documentation samples).
    bachie
    student
    php&postgresql
    Shizuoka-ken, Japan

  2. #2
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Works for me.
    How do you run this statement, i.e. which tool are you using?

  3. #3
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    You probably haven't installed plpgsql yet. Even though it's included with the install process, it isn't installed on any database until you decide what database it SHOULD be installed on.

    issue a

    Code:
    createlang plpgsql your_database_name

    SQL statement to install plpgsql on your database.

    To ensure that it gets included on any subsequent NEW databases you create, install it on template1, also.

    Ref the documentation
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  4. #4
    Join Date
    Jul 2005
    Posts
    18
    I am using PostgreSQL Maestro and WinSQL. both cannot run the script.

    Where do i need to run the createlang plpgsql workdb?

    Thanks in advance
    bachie
    student
    php&postgresql
    Shizuoka-ken, Japan

  5. #5
    Join Date
    Jul 2005
    Posts
    18
    The step by step Ive done using Putty
    1) login as: (successfully done)
    2) -bash2.05b$ psql -l (databases appear, workdb database exists)
    3) -bash2.05b$ createlang plpgsql workdb (no reply)
    4) -bash2.05b$ (after I press enter in #3).

    It is successfully done.. If yes, how to check the status of it.

    arigatou gozaimasu.
    bachie
    student
    php&postgresql
    Shizuoka-ken, Japan

  6. #6
    Join Date
    Jul 2005
    Posts
    18
    What I need to do. I follow the instructions given in the PostgreSQL Documentation.. actually the code was copy and paste to my php code.. just to test and see the sample output.

    Please assist me on this.

    thanks a lot
    bachie
    student
    php&postgresql
    Shizuoka-ken, Japan

  7. #7
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Quote Originally Posted by loquin
    I am using PostgreSQL Maestro and WinSQL. both cannot run the script.
    The statement you showed us, uses the "dollar quoting" to quote the actual code. This is something that is not done by the backend but by the client application. It seems that neither Maestor nor WinSQL support this.
    You should try it with psql.
    Btw: there is no need to connect to the server (via putty) to run psql.
    You can run psql from your client machine as well (provided you have installed it).

  8. #8
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    Or use pgAdminIII, which normally is installed with pg.

    I believe you can use the information schema to view installed languages.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •