SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict bronze trophy Hall of Famer's Avatar
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    370
    Mentioned
    6 Post(s)
    Tagged
    2 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,336
    Mentioned
    63 Post(s)
    Tagged
    3 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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict bronze trophy Hall of Famer's Avatar
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    370
    Mentioned
    6 Post(s)
    Tagged
    2 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
    5,223
    Mentioned
    153 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.

  5. #5
    SitePoint Addict bronze trophy Hall of Famer's Avatar
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    370
    Mentioned
    6 Post(s)
    Tagged
    2 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
    5,223
    Mentioned
    153 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


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
  •