#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0

    Syntax Error Help


    May you all live in peace!

    I have a little problem and I am very hopeful that I will get a solution over here.
    I have created a php page which runs this SQL statement:

    SELECT * FROM mdl_trainings WHERE manager_id = $1 AND end IS NULL
    [array (
    0 => '15',
    )]

    Here is the error I receive,

    "Error Reading Database"
    Debug info: ERROR: syntax error at or near "end"

    I hope someone here can definitely guide me what syntax error is there in the statement and how can I correct that.
    Note: The same statement works perfect for MySQL database but does not work for PostgreSQL database.

    With warm regards,

    Mahtab Hussain
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,784
    Rep Power
    348
    end is a reserved word.

    This should work:
    Code:
    SELECT * 
    FROM mdl_trainings 
    WHERE manager_id = $1 
    AND "end" IS NULL
    And please use [code] tags in the future to format your SQL code.
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags.
    http://forums.devshed.com/misc.php?do=bbcode#code

    Tips on how to ask better questions:
    http://tkyte.blogspot.de/2005/06/how-to-ask-questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0
    Originally Posted by shammat
    end is a reserved word.

    This should work:
    Code:
    SELECT * 
    FROM mdl_trainings 
    WHERE manager_id = $1 
    AND "end" IS NULL
    And please use [code] tags in the future to format your SQL code.
    Thanks Shammat. You were exactly right. I have renamed the field names to avoid reserved word and updated relevant code. It solved my issue.

    Thanks once again.

    Regards,
    Mahtab

IMN logo majestic logo threadwatch logo seochat tools logo