Postgres SELECT* FROM table WHERE column-varchar==

2019-04-18 03:29发布

问题:

I have the following table:

CREATE TABLE lawyer (
  id SERIAL PRIMARY KEY,
  name VARCHAR NOT NULL UNIQUE,
  name_url VARCHAR check(translate(name_url, 'abcdefghijklmnopqrstuvwxyz-', '') = '') NOT NULL UNIQUE
);

I want to SELECT * FROM lawyer where name_url = "john-doe"

回答1:

Character literals are put into single quotes:

SELECT * 
FROM lawyer 
where name_url = 'john-doe';

See the manual for details:
https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS