postgresql Postgres SELECT* FROM table WHERE column-varchar=="string-example"?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37868909/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:15:42  来源:igfitidea点击:

Postgres SELECT* FROM table WHERE column-varchar=="string-example"?

postgresqlpostgresql-9.1postgresql-9.3

提问by Jeka

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"

我想要 SELECT * FROM lawyer where name_url = "john-doe"

回答by a_horse_with_no_name

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

有关详细信息,请参阅手册:https:
//www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS

回答by Anto

Looking for exact match:

寻找完全匹配:

select column1, column2 from mytable where column2 like 'string';

Pattern Match can be achieved using:(returns stringxx, stringyyy..)

可以使用以下方法实现模式匹配:(返回 stringxx, stringyyy..)

select column1, column2 from mytable where column2 like 'string%';

This will return any column2 that matches string***.

这将返回匹配的任何 column2 string***

For using ORcondition, to compare multiple strings below one can be used:

对于使用OR条件,可以使用以下一个比较多个字符串:

select column1, column2 from mytable where column2 ~* 'string1|string2';