1

I have an sql table that looks like this in postgresql called test.

    date    |  data   |      source      
------------+---------+------------------
 2015-09-23 | 128     | aaamt
 2015-09-24 | 0       | aaamtx2
.....

I type SELECT * FROM test where source="aaamt" but I get the following error,

ERROR:  column "aaamt" does not exist
LINE 1: SELECT * FROM test where source = "aaamt";

Why am I getting this error and how to I fix it?

anarchy
  • 3,709
  • 2
  • 16
  • 48
  • https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS –  Oct 20 '20 at 06:07

2 Answers2

12

You need to use single quote instead of double quote

SELECT * FROM test where source = 'aaamt'
Fahmi
  • 37,315
  • 5
  • 22
  • 31
1

Double quotes indicate to Postgres that you are trying to specify an identifier such as a column or table name. Use single quotes for string literals, and your query should work:

SELECT *
FROM test
WHERE source = 'aaamt';

To be clear here, you current query is basically being interpreted as this:

SELECT *
FROM test
WHERE source = aaamt;

Here aaamt is being treated as a column name or maybe some other database identifier, but not as a string literal.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360