user740521 user740521 - 1 month ago 5x
SQL Question

How do I declare a table with a string column that has a non null default value in Postgres?

What do I need to add to make sure this table is created with the 'name' field as non null but with a value of ""?

CREATE TABLE stuff (id serial primary key, name varchar(64) <-- what goes here??


Standard SQL applies:

  id serial primary key, 
  name varchar(64) not null default ''

It's possible you attempted to use double quotes to specify the text literal like this "", which will explode. Postgres uses single quotes to delimit text literals, like this ''.

See SQLFiddle.