Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2015
    Posts
    2

    Unanswered: Simple Query Wont Work with Strings

    Hi,

    I am new to Postgres and databases in general. That said I thought that this was very simple and I cant get my head wrong why it wont work.
    All i am trying to do is run a query from within PGadmin on the database. If I run a query thats all intergers then it works everytime. Below is the real query that works for me...

    SELECT
    *
    FROM
    mydatabase.invoices
    WHERE
    invoices."InvoiceNo" = 1002758;

    I get the expect result.
    I have a column in the table 'invoices' called PaymentType. If I run the query..

    SELECT
    *
    FROM
    mydatabase.invoices
    WHERE
    invoices."PaymentType" IS NOT NULL;

    That works great, but if i run

    SELECT
    *
    FROM
    mydatabase.invoices
    WHERE
    invoices."PaymentType" = "Direct Debit";

    I get the error everytime ERROR: column "Direct Debit" does not exist
    SQL state: 42703

    But Direct Debit is a string in the PaymentType Coloumn.

    Please help!
    Andy

  2. #2
    Join Date
    Nov 2015
    Posts
    2

    Red face

    Hmm,

    Mystery solved. I was sing double quotes as opposed to inverted commas, around my strings.

    thanks anyway!
    Andy

  3. #3
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by CraftyPanda View Post
    I was sing double quotes as opposed to inverted commas, around my strings
    Yes, that's how you specify a string constant in SQL: using single quotes.

    And this is well documented in the manual: http://www.postgresql.org/docs/curre...NTAX-CONSTANTS
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags: http://www.dbforums.com/misc.php?do=bbcode#code

    Tips for good questions:

    http://tkyte.blogspot.de/2005/06/how...questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html

  4. #4
    Join Date
    Nov 2015
    Posts
    2

    Do yourself a favor

    This is just an hint:

    When you want to have a differentiation between upper case and lower case letters in table names then your solution is okay. Usually you don't want to. _Without_ quotation marks SQL is case insensitive. Then you never have to write quotation marks anymore. The database internally converts it to it's own format which is lower case letters in PostgreSQL.

    Regards
    Leuchuk

Posting Permissions

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