问题
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
回答2:
Looking for exact match:
select column1, column2 from mytable where column2 like 'string';
Pattern Match can be achieved using:(returns stringxx, stringyyy..)
select column1, column2 from mytable where column2 like 'string%';
This will return any column2 that matches string***
.
For using OR condition, to compare multiple strings below one can be used:
select column1, column2 from mytable where column2 ~* 'string1|string2';
来源:https://stackoverflow.com/questions/37868909/postgres-select-from-table-where-column-varchar-string-example