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

你。 提交于 2019-12-06 07:25:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!