Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8787457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:53:52+00:00 2026-06-13T21:53:52+00:00

Possible Duplicate: Column ‘mary’ does not exist I need to check the values that

  • 0

Possible Duplicate:
Column ‘mary’ does not exist

I need to check the values that can be accepted to a column through a check constraint. I need to use the check constraint, because this is for a college assignment.

I use this code to create and add the constraint to the table.

CREATE TABLE Ereignis(
  E_Id Serial PRIMARY KEY,
  Typ varchar(15),
  Zeitpunkt timestamp,
  Ort varchar(32),
  Anzahl_Pers int
);

ALTER TABLE Ereignis ADD 
CONSTRAINT typ_ch CHECK (Typ in (’Verkehrsunfall’, ’Hochwasser’, ’Sonstiges’));

Here is the error I get:

 ERROR:  column "’verkehrsunfall’" does not exist

As I get from this error it tries to compare column typ with column verkehrsunfall, where as I try to check the values that column try can get is one of the (’Verkehrsunfall’, ’Hochwasser’, ’Sonstiges’) strings.

This is exactly the same syntax what our lecturer showed us at the lecture. I am not sure if it is possible to compare varchars with check? Or what am I doing wrong?

Here is the example from the lecture:

CREATE TABLE Professoren 
(PersNr INTEGER PRIMARYKEY,
 Name VARCHAR( 3 0 ) NOT NULL ,
 Rang CHAR(2) CHECK (Rang in ('C2' ,'C3' ,'C4')) , 
 Raum INTEGER UNIQUE) ;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:53:53+00:00Added an answer on June 13, 2026 at 9:53 pm

    Your text editor or word processor is using so-called smart quotes, like ’, not ordinary single quotes, like '. Use ordinary single quotes (actually apostrophes) ' for literals, or double quotes " for identifiers. You also have some odd commas in there which may cause syntax errors. See the PostgreSQL manual on SQL syntax, specicifically lexical structure.

    Don’t edit SQL (or any other source code) in a word processor. A decent text editor like Notepad++, BBEdit, vim, etc, won’t mangle your SQL like this.

    Corrected example:

    CREATE TABLE Professoren 
    (PersNr INTEGER PRIMARYKEY,
     Name VARCHAR(30) NOT NULL,
     Rang CHAR(2) CHECK (Rang in ('C2' ,'C3' ,'C4')), 
     Raum INTEGER UNIQUE);
    

    The reason it doesn’t cause an outright syntax error – and instead gives you an odd error message about the column not existing – is because PostgreSQL accepts unicode column names and considers the ’ character a perfectly valid character for an identifier. Observe:

    regress=> SELECT 'dummy text' AS won’t, 'dummy2' as ’alias’;
       won’t    | ’alias’ 
    ------------+---------
     dummy text | dummy2
    (1 row)
    

    Thus, if you have a column named test and you ask for the column named ’test’, PostgreSQL will correctly tell you that there is no column named ’test’. In your case you’re asking for a column named ’verkehrsunfall’ when you meant to use the literal string Verkehrsunfall instead, hence the error message saying that the column ’verkehrsunfall’ does not exit.

    If it were a real single quote that’d be invalid syntax. The 1st wouldn’t execute in psql at all because it’d have an unclosed single quote; the 2nd would fail with something like:

    regress=>  SELECT 'dummy2' as 'alias';
    ERROR:  syntax error at or near "'alias'"
    LINE 1: SELECT 'dummy2' as 'alias';
    

    … because in ANSI SQL, that’s trying to use a literal as an identifier. The correct syntax would be with double-quotes for the identifier or no quotes at all:

    regress=> SELECT 'dummy2' as "alias", 'dummy3' AS alias;
     alias  | alias  
    --------+--------
     dummy2 | dummy3
    (1 row)
    

    You also have an unwanted space in the varchar typmod; varchar( 3 0 ) is invalid:

    regress=> SELECT 'x'::varchar( 3 0 );
    ERROR:  syntax error at or near "0"
    LINE 1: SELECT 'x'::varchar( 3 0 );
    

    BTW, in PostgreSQL it’s usually better to use a text column instead of varchar. If you want a length constraint for application or validation reasons, add a check constraint on length(colname).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Column does not exist in the IN clause, but SQL runs I
Possible Duplicate: Was: Not unique table :: Now: #1054 - Unknown column - can't
Possible Duplicate: SQL Server: Can I Comma Delimit Multiple Rows Into One Column? I
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Get column index from label in a data frame I need to
Possible Duplicate: Transposing an sql result so that one column goes onto multiple columns
Possible Duplicate: Difference of create Index by using include column or not using Edit:
Possible Duplicate: SQL Server: Can I Comma Delimit Multiple Rows Into One Column? I
Possible Duplicate: Why does column = NULL return no rows? I am trying to
Possible Duplicate: Need to update the value of a column in SQLite Hi all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.