I have this SQL
query that I'm writing using Postgresql
.
select * from cdr_data
where REGEXP_LIKE(identifiant,'^73')
and REGEXP_REPLACE(callednumber,'^256','') ~ '^73'
It gives me following error:
[Err] ERROR: function regexp_like(character varying, unknown) does not exist
LINE 2: and regexp_like(identifiant,'^73')
I have tried replace with REGEXP_LIKE
with LIKE
and REGEXP_MATCHES
but they don't work.
What could be the problem?
PostgreSQL相当于regexp_like(identifiant,'^73')
可identifiant ~ '^73'
Have you tried using SIMILAR TO
operator?
Some snippets from PostgreSQL documentation:
a. `select 'abc' SIMILAR TO '(a|d)%';`
b. `select 'def' SIMILAR TO '(a|b|c)%';`
Statement a returns t
(true) as 'abc' starts with 'a' or 'd'. Statement b returns f
(false) as 'def' doesn't start with either 'a' or 'b' or 'c'.
In fact, you can use one of following functions
value_or_colum_name ~ '<regex-expression>'
value_or_colum_name SIMILAR TO '<regex-expression>'
TEXTREGEXEQ(value_or_colum_name,'<regex-expression>')
all these 3 possibilities are totaly equivalent.
The REGEXP_LIKE
fonction doesn't exists on SqlPostGreSQL. But REGEXP_MATCHES
and REGEXP_REPLACE
exist.
Here is a command using ~
and REGEXP_REPLACE
that I used to check if my Regular Expresion work correctly before starting an SQL UPDATE
.
SELECT communication
,REGEXP_REPLACE
(communication
,'(\d{3})(\d{4})(\d{5})'
,'***\1/\2/\3***'
) as ref
FROM mouvements
WHERE communication ~ '^\d{12}$'
this give following results
comm ref
------------------------------------
303000167868 ***303/0001/67868***
121231357408 ***121/2313/57408***
321000204456 ***321/0002/04456***
and the final UPDATE command is
UPDATE mouvements
SET communication = NULL
,Ref_Structured = REGEXP_REPLACE(communication,'(\d{3})(\d{4})(\d{5})','***\1/\2/\3***')
WHERE communication ~ '^\d{12}$'
another SQL UPDATE
command that split a column is 2
UPDATE mouvements
SET nom = REGEXP_REPLACE(nom,'^(.*)(REFERENCE DONNEUR D''ORDRE : )(.*)','\1')
,RefDonneur = REGEXP_REPLACE(nom,'^.*(REFERENCE DONNEUR D''ORDRE : )(.*)','\2')
where nom ~ 'REFERENCE DONNEUR D''ORDRE :'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.