1

I have a table called Foo, which I'm trying to add a column "bar" to. Using psycopg2 in python, my function call is

cursor.execute('ALTER TABLE "Foo" ADD COLUMN bar text')

However, I get the following error:

relation "Foo" does not exist

I also tried putting the schema "public" before it to no avail. What am I doing wrong? Thanks.

Edit:

CraigRinger's command \dt *.?oo yielded No matching relations found

\dt *.foo and \dt *.Foo both yielded the following output:

     List of relations
Schema |Name|Type |Owner
-------+----+-----+--------
public |foo |table|postgres
6
  • quoting an identifier makes it case sensitive, are you sure your table isn't actually named foo? check the last paragraph of section 4.1.1 Commented Aug 11, 2015 at 23:18
  • 1
    In psql what's the output of \dt *.?oo ? Commented Aug 11, 2015 at 23:41
  • No matching relations found. Did you mean \dt *.foo ? Commented Aug 11, 2015 at 23:58
  • With this command I see the table under schema public Commented Aug 12, 2015 at 0:08
  • 1
    Your answer to @CraigRinger seems confusing to me. His command should have returned all tables in any schema starting with any char and ending in 'oo'. Also if you gave command \dt *.foo and you did see a table, then it must be named foo not Foo. Could you update your question to include the \dt command you gave and the complete output you got? Commented Aug 12, 2015 at 4:10

1 Answer 1

1

You table is named foo, not Foo. If you use the quoted name "Foo" then postgres treats it case sensitive and therfore doesn't find it.

Postgres treats all unquoted names as if they were lower case, that is Foo is the same as foo, as are FOO and "foo", however "Foo" is not the same.

This is explicitly mentioned in the documentation:

Quoting an identifier also makes it case-sensitive, whereas unquoted names are always folded to lower case. For example, the identifiers FOO, foo, and "foo" are considered the same by PostgreSQL, but "Foo" and "FOO" are different from these three and each other. (The folding of unquoted names to lower case in PostgreSQL is incompatible with the SQL standard, which says that unquoted names should be folded to upper case. Thus, foo should be equivalent to "FOO" not "foo" according to the standard. If you want to write portable applications you are advised to always quote a particular name or never quote it.)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.