Coditional选择postgresql DB错误

时间:2022-10-25 22:46:54

I used postgresql DB.
This order is working.

我使用了postgresql DB。这个订单正在运作。

# select * from test where id=3299;
   id   |  m_id  | old_code  | new_code  |          log_date
--------+--------+-----------+-----------+----------------------------
  3299  | 603990 | 220088242 | 234024141 | 2018-08-09 18:40:05.655615
(1 row)

but, other condition's this order is not working.

但是,其他条件的顺序不起作用。

# select * from test where old_code = "220088242";
ERROR:  column "220088242" does not exist
LINE 1: select * from test where old_code = "220088242";

this is DB's detail.

这是DB的细节。

# \d test;
                                   Table "test"
  Column  |            Type             |                          Modifiers

-----------------
 id       | integer                     | not null default nextval('test_id
_seq'::regclass)
 m_id     | integer                     |
 old_code | character varying(12)       |
 new_code | character varying(12)       |
 log_date | timestamp without time zone |
Indexes:
"l_shina_pkey" PRIMARY KEY, btree (id)

what is problem? I don't know what is problem...
thanks in advance.

什么问题?我不知道有什么问题......提前谢谢。

2 个解决方案

#1


2  

in postgresql " " could be used to refer to a column or table named "select"

在postgresql中“”可用于引用名为“select”的列或表

A string constant in SQL is an arbitrary sequence of characters bounded by single quotes ('), for example 'This is a string'.so this is not the same as a double-quote character (")

SQL中的字符串常量是由单引号(')限定的任意字符序列,例如'This is a string'。这与双引号字符(“)不同

As a result you have to use single quote like below

因此,您必须使用如下单引号

select * from test where old_code = '220088242'

#2


0  

use like clause

使用like子句

SELECT * FROM test WHERE old_code LIKE '220088242';

#1


2  

in postgresql " " could be used to refer to a column or table named "select"

在postgresql中“”可用于引用名为“select”的列或表

A string constant in SQL is an arbitrary sequence of characters bounded by single quotes ('), for example 'This is a string'.so this is not the same as a double-quote character (")

SQL中的字符串常量是由单引号(')限定的任意字符序列,例如'This is a string'。这与双引号字符(“)不同

As a result you have to use single quote like below

因此,您必须使用如下单引号

select * from test where old_code = '220088242'

#2


0  

use like clause

使用like子句

SELECT * FROM test WHERE old_code LIKE '220088242';