Skip to content
Advertisement

PostgreSQL UPDATE statement treats keyword as a column

sorry for the noob question, just getting started with SQL and I have a problem that I could not resolve. Basically, I created a table with “date of birth” column and chose wrong TYPE (integer), so every time I am trying to enter date of birth as “1998-01-04” it is just showing 1998. So, I decided to update the column to TEXT type. Tried these queries

UPDATE users
SET date_of_birth = VARCHAR

It shows me error that there are no VARCHAR columns. Tried with as ‘VARCHAR’, still not working, tried as ‘TEXT’ and TEXT, still the same error. What am I doing wrong?

Advertisement

Answer

Strings are as bad or worse than integers for this purpose. You want to use:

alter table alter column date_of_birth type date;

Note: If you have existing data in the column, you need to either use the using clause to convert it to a date. Or NULL it all out.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement