Postgres Like声明无法正确阅读

时间:2018-04-15 11:20:05

标签: sql database postgresql

我一直试图找出为什么这个LIKE语句无法正确读取。

CREATE VIEW sole_python_author(author_first_name, author_last_name,book_title)
AS SELECT
authors.first_name,authors.last_name, books.title
FROM authors, books
WHERE books.author_id = authors.author_id AND  books.title LIKE '%python%';

如果我删除'python',则示例输出为:

author_first_name | author_last_name |         book_title          
-------------------+------------------+-----------------------------
 Stephen           | King             | The Shining
 Frank             | Herbert          | Dune
 Arthur C.         | Clarke           | 2001: A Space Odyssey
 Seuss             | Theodor          | The Cat in the Hat
 Seuss             | Theodor          | Bartholomew and the Oobleck
 Paulette          | Bourgeois        | Franklin in the Dark
 Margaret Wise     | Brown            | Goodnight Moon
 Louisa May        | Alcott           | Little Women
 Margery Williams  | Bianco           | The Velveteen Rabbit
 Burne             | Hogarth          | Dynamic Anatomy
 Edgar Allen       | Poe              | The Tell-Tale Heart
 Mark              | Lutz             | Programming Python
 Mark              | Lutz             | Learning Python
 Tom               | Christiansen     | Perl Cookbook
 John              | Worsley          | Practical PostgreSQL

然而,当我在代码中添加'python'时,它返回0行。我认为问题在于同样的陈述,但我不确定。我正在尝试获得如下输出:

 Mark              | Lutz             | Programming Python
 Mark              | Lutz             | Learning Python

或者我的陈述是否正确执行,输出应为0行?

2 个答案:

答案 0 :(得分:1)

import pyqtgraph as pg import numpy as np import math from pyqtgraph.Qt import QtCore, QtGui class Graph(pg.GraphItem): def __init__(self): ... # Construct a unit radius circle for the graph class EllipseObject(QtGui.QGraphicsObject): sigClicked = QtCore.pyqtSignal(float, float) def __init__(self, center= (0.0, 0.0), radius=1.0, pen=QtGui.QPen(QtCore.Qt.white)): QtGui.QGraphicsObject.__init__(self) self.center = center self.radius = radius self.pen = pen def boundingRect(self): rect = QtCore.QRectF(0, 0, 2*self.radius, 2*self.radius) rect.moveCenter(QtCore.QPointF(*self.center)) return rect def paint(self, painter, option, widget): painter.setPen(self.pen) painter.drawEllipse(self.boundingRect()) def mousePressEvent(self, event): p = event.pos() self.sigClicked.emit(p.x(), p.y()) QtGui.QGraphicsEllipseItem.mousePressEvent(self, event) if __name__ == '__main__': position = [(-0.5,0), (0.5,0)] adjacency = [(0,1)] w = pg.GraphicsWindow() w.setWindowTitle('Title of the window') v = w.addViewBox() v.setAspectLocked() g = Graph() v.addItem(g) g.setData(pos=np.array(position), adj=np.array(adjacency), pxMode=False, size=0.1) item = EllipseObject() item.sigClicked.connect(lambda x, y: print(x, y)) v.addItem(item) import sys if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): QtGui.QApplication.instance().exec_() 关键字以区分大小写的方式匹配字符串。 我想您要使用与LIKE类似的ILIKE,但不区分大小写。

答案 1 :(得分:1)

LIKE关键字区分大小写。

books.title LIKE '%Python%'

LOWER(books.title) LIKE '%python%'

或者

books.title ILIKE '%python%'