SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict bronze trophy
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    342
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)

    PGMyadmin create trigger, syntax error neat BEGIN

    Well I am trying to create a trigger, but it seems that using PGMyadmin's SQL command prompt wont work, it shows syntax error all the time:

    PHP Code:
    CREATE TRIGGER trigger_name BEFORE INSERT ON table_name
        
    FOR EACH ROW
        BEGIN
            
    // Code inside
        
    END
    Anyone knows how to fix this problem? I have absolutely no idea why this syntax error appears:
    ERROR: syntax error at or near "BEGIN"
    LINE 3: BEGIN
    ^

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,022
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by Hall of Famer View Post
    Anyone knows how to fix this problem?
    i would start by looking up the CREATE TRIGGER syntax in da manual --

    http://www.postgresql.org/docs/8.1/s...tetrigger.html
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict bronze trophy
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    342
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Yeah I made sure to check the syntax and found nothing wrong with it.

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,827
    Mentioned
    142 Post(s)
    Tagged
    0 Thread(s)
    From the manual, it seems a TRIGGER can ONLY execute a function in PostgresSQL
    CREATE TRIGGER creates a new trigger. The trigger will be associated with the specified table and will execute the specified function funcname when certain events occur.
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  5. #5
    SitePoint Addict bronze trophy
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    342
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by cpradio View Post
    From the manual, it seems a TRIGGER can ONLY execute a function in PostgresSQL
    Well the Manual says that its possible to use FOR EACH ROW statement, weird.

  6. #6
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,827
    Mentioned
    142 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Hall of Famer View Post
    Well the Manual says that its possible to use FOR EACH ROW statement, weird.
    Yes, but following that must be EXECUTE funcname (arguments) not BEGIN
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes


Bookmarks

Posting Permissions

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