Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL sql command error column 'does not exist'

Tags:

insert

dxdb=> \d dxtest_loadprofiletosale
                            Table "public.dxtest_loadprofiletosale"
   Column    |   Type   |                               Modifiers                               
-------------+----------+-----------------------------------------------------------------------
 id          | integer  | not null default nextval('dxtest_loadprofiletosale_id_seq'::regclass)
 TransDate   | date     | 
 IssueDate   | date     | 
 CustomerNum | smallint | not null
Indexes:
    "dxtest_loadprofiletosale_pkey" PRIMARY KEY, btree (id)

dxdb=> INSERT INTO dxtest_loadprofiletosale(id, TransDate, IssueDate, CustomerNum) VALUES(1, '2015-03-04','2015-01-01',01);
ERROR:  column "transdate" of relation "dxtest_loadprofiletosale" does not exist
LINE 1: INSERT INTO dxtest_loadprofiletosale(id, TransDate, IssueDat...

excuse me,I already has the column "transdate", why it said does not exist?

like image 943
Joe Lin Avatar asked Mar 04 '15 07:03

Joe Lin


People also ask

What does “column does not exist” mean in PostgreSQL?

It will be seen along with the error message “column does not exist”. This error indicates either that the requested column does not exist, or that the query is not correct. Here at Bobcares, we often handle requests from our customers to fix similar PostgreSQL errors as a part of our Server Management Services.

What does this error indicate in PostgreSQL?

This error indicates either that the requested column does not exist, or that the query is not correct. Here at Bobcares, we often handle requests from our customers to fix similar PostgreSQL errors as a part of our Server Management Services.

Are PostgreSQL column names case sensitive?

PostgreSQL columns (object) names are case sensitive when specified with double quotes. Unquoted identifiers are automatically used as lowercase so the correct case sequence must be written with double quotes. When used with quotes, Postgresql is case sensitive regarding identifier names like table names and column names.

What is the column does not exist exception in SQL?

The column does not exist exception occurs when a column does not exist in the table. If the searching column does not exist in the table then it will raise the exception that the column does not exist in the table.


1 Answers

Your column is called "TransDate" not transdate. You created your table using double quotes for the column names, which makes them case sensitive and you must use double quotes all the time:

INSERT INTO dxtest_loadprofiletosale
  (id, "TransDate", "IssueDate", "CustomerNum") 
VALUES
  (1, '2015-03-04','2015-01-01',01);

More details about SQL identifiers are in the manual:
http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

In general it is better to never use double quotes - it will give you a lot less trouble in the long run.

like image 70
a_horse_with_no_name Avatar answered Jan 01 '23 13:01

a_horse_with_no_name