need to hardcode a column in Hive with a custom word appending along with a column_name from a table - sql

select distinct 'CART-data-map_val.role_name' as ProdMN
from VRN_544.RLT_001 AS mk_roles
JOIN VRMM.map_valxx AS map_val
ON ( Upper(Trim(map_val.role_name)) = Upper(Trim(mk_roles.rltx_02)) )
so, CART-data is the word which should append to the role_name into ProdMN column
ProdMN column Example - CART-data-map_val.role_name - 1- CART-data-reducer-role
2- CART-data-modular-role

how about using concat ?:
select distinct concat('CART-data-',map_val.role_name) as ProdMN
from VRN_544.RLT_001 AS mk_roles
JOIN VRMM.map_valxx AS map_val
ON ( Upper(Trim(map_val.role_name)) = Upper(Trim(mk_roles.rltx_02)) )

Related

Spark SQL column doesn't exist

I am using Spark in databricks for this SQL command.
In the input_data table, I have a string for the st column. Here I want to do some calculations of the string length.
However, after I assign the length_s alias to the first column, I can not call it in the following columns. SQL engine gives out Column 'length_s1' does not exist error message. How can I fix this?
CREATE OR REPLACE VIEW content_data (SELECT LENGTH(st) AS length_s, LENGTH(st)-LENGTH(REGEXP_REPLACE(seq,'[AB]','')) AS AB_c,
length_s - LENGTH(REGEXP_REPLACE(seq, '[CD]', '') AS CD_c, CD_c+AB_c AS sum_c
FROM input_data)
You can't use aliases in the same select
So do
CREATE OR REPLACE VIEW content_data (
SELECT
LENGTH(st) AS length_s
, LENGTH(st)-LENGTH(REGEXP_REPLACE(seq,'[AB]','')) AS AB_c,
LENGTH(st) - LENGTH(REGEXP_REPLACE(seq, '[CD]', '') AS CD_c
, LENGTH(st) - LENGTH(REGEXP_REPLACE(seq, '[CD]', '') + LENGTH(st)-LENGTH(REGEXP_REPLACE(seq,'[AB]','')) AS sum_c
FROM input_data
)

Simulating an if condition in the WHERE clause of an SQL query

I am trying to write a google BigQuery to select some records based on this condition:
if ID_parameter is not null:
SELECT * WHERE ID=ID_parameter
else:
SELECT * WHERE country_id=country_id_parameter and (name LIKE %name_parameter% OR name is null)
The name_parameter should be optional but one of the ID_parameter or country_id_parameter must be provided.
Sorry, I am a newbie with SQL but I hope I stated what I want clearly.
consider below approach
select *
from your_table
where case
when not id_parameter is null then id = id_parameter
else country_id = country_id_parameter and (regexp_contains(name, name_parameter) or name is null)
end
I miss the table name in the query, let's assume it's 'personnel'.
Suppose ID-parameter = 200, country_id_parameter = 'NL', name_parameter = '%bart%'
Maybe like this when the name is 'bart':
select * from personnel
where ID=200
or (ID=NULL and
country_id='NL' and
name LIKE '%bart%')
Use this when the name is NULL:
select * from personnel
where ID=200
or (ID=NULL and
country_id='NL')

Merge 3 columns into 1 with multiple nested select

I have some data that i need to display on a path layer on deckgl inside super set, the format of the data has to be very specific or else it throws errors, the format is as such
[[],[],[]] anything else will throw errors. My data is in long and lat format which i was able to transform in to proper form, except that some lines are multistring which has this format [[[],[]],[[]]]. i am able to get it into proper format separately in 3 different columns, how do i merge these 3 into 1? tried union distinct by basing my self on this example, with an error "Expected keyword JOIN but got "," at [3:98]" how do i solve this?
SELECT * FROM Employee_Asia UNION DISTINCT SELECT * from
Employee_Europe
****
select * from(
(select replace(substring(geo,1),"[[[", "[[") as ngeo union
DISTINCT
(select replace
(substring(geo,1),"]]]", "]]")) union DISTINCT select replace
(substring(geo,1),"]],[[" ,"], [")), from(
****
select replace(substring(geo,1),"[[[", "[[") as ngeo, (select replace
(substring(geo,1),"]]]", "]]"))as xgeo, (select replace (substring(geo,1),"]],[[" ,"],
["))as zgeo,from(
select geo from (
SELECT
routeID , json_extract(st_asgeojson(st_makeline( array_agg(st_geogpoint(locs.lon,
locs.lat) order by locs.date))),'$.coordinates') as geo,
FROM
howardcounty.routebatches
cross join UNNEST(locations) as locs
where locs.date between {{start_date}} and {{end_date}}
group by routeID
order by routeID
limit 7
)where length(geo)-length(replace(geo,"]","")) > 1+4
)
here is a the result from the query without union, am also limited to select only.
[[-76.832895,39.20946],[-76.8328744528093,39.2094841310634],
[-76.8327537674778,39.2096258661087],[-76.8327516666667,39.2096283333333],
[-76.8326516666667,39.20973],[-76.8326416666667,39.2098316666667],
[-76.8327033333333,39.2099316666667],[-76.83284,39.2099916666667],
[-76.8329033333333,39.210025],[-76.8331,39.2101616666667],
[-76.8332383333333,39.2102366666667],[-76.8333933333333,39.2103233333333],
[-76.8335416666667,39.2103883333333],[-76.8336783333333,39.21044],
[-76.8338,39.2104816666667],[-76.83389,39.2105533333333],
[-76.83389633091,39.2105767090203],[-76.8339113352774,39.2106321097435],
[-76.8339116666667,39.2106333333333],[-76.8338887881129,39.2106764906686],
[-76.8338383333333,39.2107716666667],[-76.8337783333333,39.2108866666667],
[-76.8337710512136,39.2110192012812],[-76.83377,39.2110383333333],
[-76.8338232468397,39.2111109427531],[-76.83388,39.2111883333333],
[-76.8340466666667,39.2111883333333],[-76.834145,39.211135],
[-76.8341866666667,39.2110433333333],[-76.8342116666667,39.2110016666667],
[-76.83428,39.2108766666667],[-76.8343283333333,39.210795],[-76.83439,39.2107266666667],
[-76.8344492363899,39.2106641394387],[-76.83451,39.2106],[-76.834715,39.21045],
[-76.8349033333333,39.2103033333333],[-76.83497,39.21014],[-76.8349733333333,39.21006],
[-76.834985,39.21022],[-76.834865,39.2104133333333],[-76.83476,39.21059],
[-76.8347916666667,39.21075],[-76.8350466666667,39.2108316666667],
[-76.8352283333333,39.2107116666667],[-76.83532,39.2105266666667],
[-76.8354483333333,39.2103633333333],[-76.83555,39.21017],
[-76.8356666666667,39.2100466666667],[-76.8358216666667,39.21004],
[-76.8358733333333,39.2101316666667],[-76.8358316666667,39.2102883333333],
[-76.8359,39.210425],[-76.8358689842204,39.2104852071477],[-76.8358433333333,39.210535],
[-76.8356983333333,39.210565],[-76.8357383333333,39.210475],
[-76.8358689842204,39.2104852071477],[-76.8359516666667,39.2104916666667],
[-76.8360516666667,39.210455],[-76.8361533333333,39.2102916666667],
[-76.836285,39.210175],[-76.8364766666667,39.21023],[-76.8366683333333,39.21028],
[-76.8368166666667,39.210305],[-76.836955,39.2103233333333],
[-76.83699,39.2103183333333],[-76.8373016666667,39.2103166666667],
[-76.8374566666667,39.2103016666667],[-76.8376066666667,39.21029],
[-76.8377616666667,39.2103016666667],[-76.83795,39.210335],
[-76.8381333333333,39.2104033333333],[-76.83831,39.2105133333333],
[-76.8384333333333,39.2106416666667],[-76.8385183333333,39.210785],
[-76.8385616666667,39.210935],[-76.838585,39.2110366666667],
[-76.8386083333334,39.2111266666667],[-76.83865,39.211245],
[-76.8387166666667,39.211505],[-76.838855,39.2116916666667],
[-76.839035,39.2118216666667],[-76.8392,39.2119766666667],[-76.8393516666667,39.212125],
[-76.83948,39.21218],[-76.8395733333333,39.2121633333333],
[-76.8398377180994,39.212155736099],[-76.839863333316,39.2121550000005],
[-76.8398633333333,39.212155],[-76.839866248213,39.2121550000002],
[-76.8398683333333,39.212155],[-76.839885,39.212155]],
[[-76.839863333316,39.2121550000005],[-76.83984,39.212155],
[-76.8398377180994,39.212155736099],[-76.839685,39.212205],
[-76.8395033333333,39.212245],[-76.83924,39.2121616666667],
[-76.8390316666667,39.2119483333333],[-76.8388216666667,39.2117766666667],
[-76.8387066666667,39.21161],[-76.838545,39.21148],[-76.8383866666667,39.211435],
[-76.8381966666667,39.2114216666667],[-76.8380266666667,39.21142],
[-76.8378533333333,39.2114133333333],[-76.8376933333333,39.2114116666667],
[-76.837545,39.2113983333333],[-76.837365,39.2114166666667],
[-76.837145,39.2113883333333],[-76.83696,39.2113683333333],[-76.8368116666667,39.21135],
[-76.8366616666667,39.211345],[-76.8365166666667,39.21134],
[-76.836395,39.2113383333333],[-76.83635,39.21134],[-76.8361416666667,39.21133],
[-76.8359466666667,39.2112916666667],[-76.8358183333333,39.2112233333333],
[-76.8357733333333,39.2111683333333],[-76.8357366666667,39.211055],
[-76.8356816666667,39.2109716666667],[-76.83552,39.211005],
[-76.8353483333333,39.2109983333333],[-76.8351966666667,39.2109416666667],
[-76.835055,39.210885],[-76.8349033333333,39.21081],[-76.83475,39.2107766666667],
[-76.834625,39.2107333333333],[-76.83449,39.2106866666667],
[-76.8344492363899,39.2106641394387],[-76.8343633333333,39.2106166666667],
[-76.834205,39.21054],[-76.8340283333333,39.2105483333333],
[-76.833938122743,39.2106129286176],[-76.8339113352774,39.2106321097435],
[-76.8338933333333,39.210645],[-76.8338216666667,39.2107666666667],
[-76.83377,39.2108516666667],[-76.8337333333333,39.2109116666667],
[-76.8337122666612,39.2109696000596],[-76.8336933333333,39.2110216666667],
[-76.8337276727651,39.2110803760451],[-76.833745,39.21111],
[-76.8338232468397,39.2111109427531],[-76.8338833333333,39.2111116666667],
[-76.83392,39.211055],[-76.8339716666667,39.2109833333333],
[-76.8340783333333,39.2108283333333],[-76.8340766666667,39.210725],
[-76.8339833333333,39.2106566666667],[-76.8339611067922,39.2106613270793],
[-76.8338887881129,39.2106764906686],[-76.83388,39.2106783333333],
[-76.8338083333333,39.2108016666667],[-76.83373,39.2109366666667],
[-76.8337122666612,39.2109696000596],[-76.83366,39.2110666666667],
[-76.8335933333333,39.21119],[-76.8335266666667,39.211375],[-76.83353,39.2116183333333],
[-76.833635,39.2118683333333],[-76.8338283333333,39.212085],
[-76.8340583333333,39.2123116666667],[-76.8342483333333,39.21253],[-76.834345,39.21274],
[-76.8344233333333,39.212935],[-76.8343933333333,39.21316],
[-76.8345383333333,39.2133166666667],[-76.8347266666667,39.213195],
[-76.8345933333333,39.2129983333333],[-76.834455,39.2127816666667],
[-76.8343833333333,39.212615],[-76.834365,39.2125766666667],
[-76.83429,39.2124883333333],[-76.83412,39.21229],[-76.8339066666667,39.2120766666667],
[-76.8337066666667,39.21187],[-76.8336,39.2116516666667],
[-76.8335816666667,39.2114666666667],[-76.8336083333333,39.211325],
[-76.8336516666667,39.2112016666667],[-76.8337066666667,39.21111],
[-76.8337276727651,39.2110803760451],[-76.8337710512136,39.2110192012812],
[-76.8337716666667,39.2110183333333],[-76.8338516666667,39.2109],
[-76.83392,39.2108133333333],[-76.83396,39.2107166666667],
[-76.8339611067922,39.2106613270793],[-76.8339616666667,39.2106333333333],
[-76.833938122743,39.2106129286176],[-76.83389633091,39.2105767090203],
[-76.8338866666667,39.2105683333333],[-76.833715,39.2105016666667],
[-76.833595,39.2104533333333],[-76.83358,39.21045],[-76.833405,39.2103716666667],
[-76.83337,39.210365],[-76.8332116666667,39.2103166666667],[-76.8330966666667,39.21027],
[-76.83299,39.2102233333333],[-76.83286,39.2101766666667],
[-76.8327283333333,39.2101333333333],[-76.8325683333333,39.2100616666667],
[-76.832535,39.2100016666667],[-76.8325183333333,39.2098966666667],
[-76.8325066666667,39.2097333333333],[-76.8324919958592,39.209720248584],
[-76.8323833333333,39.2096233333333],[-76.8321633333333,39.2095333333333],
[-76.8320825997553,39.20948763515],[-76.8319866666667,39.2094333333333],
[-76.8319816666667,39.2092766666667],[-76.83207,39.2091466666667],[-76.832225,39.20905],
[-76.8323483333333,39.2091416666667],[-76.8322416666667,39.2093283333333],
[-76.8321066666667,39.209475],[-76.8320825997553,39.20948763515],
[-76.8319733333333,39.209545],[-76.831862668414,39.20954057341],
[-76.8318483333334,39.20954],[-76.8318415539569,39.2095171966764],
[-76.8318116666667,39.2094166666667],[-76.8318683333333,39.2093033333333],
[-76.8319233333333,39.209195],[-76.8318483333334,39.2091033333333],
[-76.8317466666667,39.2090916666667],[-76.8317216666667,39.209135],
[-76.8317866666667,39.2093583333333],[-76.83182,39.2094933333333],
[-76.8318415539569,39.2095171966764],[-76.831862668414,39.20954057341],
[-76.8319133333333,39.2095966666667],[-76.8318683333333,39.2097],
[-76.8318416666667,39.2097383333333],[-76.8318116666667,39.2098966666667],
[-76.8319366666667,39.2099516666667],[-76.832085,39.21],[-76.83213,39.21008],
[-76.8322416666667,39.2101083333333],[-76.832365,39.2100483333333],
[-76.8324283333333,39.20996],[-76.832475,39.209885],[-76.83249,39.20984],
[-76.8324919958592,39.209720248584],[-76.8324924676826,39.2096919391536],
[-76.8324933333333,39.20964],[-76.8325983333333,39.2094983333333],
[-76.8326833333333,39.2093466666667],[-76.83268,39.2091916666667],
[-76.8324833333333,39.2091266666667],[-76.8323283333333,39.2092133333333],
[-76.83233,39.209355],[-76.8323516666667,39.209475],
[-76.8323933333333,39.2096216666667],[-76.8324924676826,39.2096919391536],
[-76.832525,39.209715],[-76.8326783333333,39.2096816666667],
[-76.8327537674778,39.2096258661087],[-76.8328,39.2095916666667],
[-76.8328766666667,39.2095216666667],[-76.8329,39.20949],
[-76.8328744528093,39.2094841310634],[-76.8327766666667,39.2094616666667],
[-76.8327466666667,39.2095066666667],[-76.832685,39.209635],
[-76.83268,39.2096466666667]]] [[[-76.832895,39.20946],
[-76.8328744528093,39.2094841310634],[-76.8327537674778,39.2096258661087],
[-76.8327516666667,39.2096283333333],[-76.8326516666667,39.20973],
[-76.8326416666667,39.2098316666667],[-76.8327033333333,39.2099316666667],
[-76.83284,39.2099916666667],[-76.8329033333333,39.210025],[-76.8331,39.2101616666667],
[-76.8332383333333,39.2102366666667],[-76.8333933333333,39.2103233333333],
[-76.8335416666667,39.2103883333333],[-76.8336783333333,39.21044],
[-76.8338,39.2104816666667],[-76.83389,39.2105533333333],
[-76.83389633091,39.2105767090203],[-76.8339113352774,39.2106321097435],
[-76.8339116666667,39.2106333333333],[-76.8338887881129,39.2106764906686],
[-76.8338383333333,39.2107716666667],[-76.8337783333333,39.2108866666667],
[-76.8337710512136,39.2110192012812],[-76.83377,39.2110383333333],
[-76.8338232468397,39.2111109427531],[-76.83388,39.2111883333333],
[-76.8340466666667,39.2111883333333],[-76.834145,39.211135],
[-76.8341866666667,39.2110433333333],[-76.8342116666667,39.2110016666667],
[-76.83428,39.2108766666667],[-76.8343283333333,39.210795],[-76.83439,39.2107266666667],
[-76.8344492363899,39.2106641394387],[-76.83451,39.2106],[-76.834715,39.21045],
[-76.8349033333333,39.2103033333333],[-76.83497,39.21014],[-76.8349733333333,39.21006],
[-76.834985,39.21022],[-76.834865,39.2104133333333],[-76.83476,39.21059],
[-76.8347916666667,39.21075],[-76.8350466666667,39.2108316666667],
[-76.8352283333333,39.2107116666667],[-76.83532,39.2105266666667],
[-76.8354483333333,39.2103633333333],[-76.83555,39.21017],
[-76.8356666666667,39.2100466666667],[-76.8358216666667,39.21004],
[-76.8358733333333,39.2101316666667],[-76.8358316666667,39.2102883333333],
[-76.8359,39.210425],[-76.8358689842204,39.2104852071477],[-76.8358433333333,39.210535],
[-76.8356983333333,39.210565],[-76.8357383333333,39.210475],
[-76.8358689842204,39.2104852071477],[-76.8359516666667,39.2104916666667],
[-76.8360516666667,39.210455],[-76.8361533333333,39.2102916666667],
[-76.836285,39.210175],[-76.8364766666667,39.21023],[-76.8366683333333,39.21028],
[-76.8368166666667,39.210305],[-76.836955,39.2103233333333],
[-76.83699,39.2103183333333],[-76.8373016666667,39.2103166666667],
[-76.8374566666667,39.2103016666667],[-76.8376066666667,39.21029],
[-76.8377616666667,39.2103016666667],[-76.83795,39.210335],
[-76.8381333333333,39.2104033333333],[-76.83831,39.2105133333333],
[-76.8384333333333,39.2106416666667],[-76.8385183333333,39.210785],
[-76.8385616666667,39.210935],[-76.838585,39.2110366666667],
[-76.8386083333334,39.2111266666667],[-76.83865,39.211245],
[-76.8387166666667,39.211505],[-76.838855,39.2116916666667],
[-76.839035,39.2118216666667],[-76.8392,39.2119766666667],[-76.8393516666667,39.212125],
[-76.83948,39.21218],[-76.8395733333333,39.2121633333333],
[-76.8398377180994,39.212155736099],[-76.839863333316,39.2121550000005],
[-76.8398633333333,39.212155],[-76.839866248213,39.2121550000002],
[-76.8398683333333,39.212155],[-76.839885,39.212155]],
[[-76.839863333316,39.2121550000005],[-76.83984,39.212155],
[-76.8398377180994,39.212155736099],[-76.839685,39.212205],
[-76.8395033333333,39.212245],[-76.83924,39.2121616666667],
[-76.8390316666667,39.2119483333333],[-76.8388216666667,39.2117766666667],
[-76.8387066666667,39.21161],[-76.838545,39.21148],[-76.8383866666667,39.211435],
[-76.8381966666667,39.2114216666667],[-76.8380266666667,39.21142],
[-76.8378533333333,39.2114133333333],[-76.8376933333333,39.2114116666667],
[-76.837545,39.2113983333333],[-76.837365,39.2114166666667],
[-76.837145,39.2113883333333],[-76.83696,39.2113683333333],[-76.8368116666667,39.21135],
[-76.8366616666667,39.211345],[-76.8365166666667,39.21134],
[-76.836395,39.2113383333333],[-76.83635,39.21134],[-76.8361416666667,39.21133],
[-76.8359466666667,39.2112916666667],[-76.8358183333333,39.2112233333333],
[-76.8357733333333,39.2111683333333],[-76.8357366666667,39.211055],
[-76.8356816666667,39.2109716666667],[-76.83552,39.211005],
[-76.8353483333333,39.2109983333333],[-76.8351966666667,39.2109416666667],
[-76.835055,39.210885],[-76.8349033333333,39.21081],[-76.83475,39.2107766666667],
[-76.834625,39.2107333333333],[-76.83449,39.2106866666667],
[-76.8344492363899,39.2106641394387],[-76.8343633333333,39.2106166666667],
[-76.834205,39.21054],[-76.8340283333333,39.2105483333333],
[-76.833938122743,39.2106129286176],[-76.8339113352774,39.2106321097435],
[-76.8338933333333,39.210645],[-76.8338216666667,39.2107666666667],
[-76.83377,39.2108516666667],[-76.8337333333333,39.2109116666667],
[-76.8337122666612,39.2109696000596],[-76.8336933333333,39.2110216666667],
[-76.8337276727651,39.2110803760451],[-76.833745,39.21111],
[-76.8338232468397,39.2111109427531],[-76.8338833333333,39.2111116666667],
[-76.83392,39.211055],[-76.8339716666667,39.2109833333333],
[-76.8340783333333,39.2108283333333],[-76.8340766666667,39.210725],
[-76.8339833333333,39.2106566666667],[-76.8339611067922,39.2106613270793],
[-76.8338887881129,39.2106764906686],[-76.83388,39.2106783333333],
[-76.8338083333333,39.2108016666667],[-76.83373,39.2109366666667],
[-76.8337122666612,39.2109696000596],[-76.83366,39.2110666666667],
[-76.8335933333333,39.21119],[-76.8335266666667,39.211375],[-76.83353,39.2116183333333],
[-76.833635,39.2118683333333],[-76.8338283333333,39.212085],
[-76.8340583333333,39.2123116666667],[-76.8342483333333,39.21253],[-76.834345,39.21274],
[-76.8344233333333,39.212935],[-76.8343933333333,39.21316],
[-76.8345383333333,39.2133166666667],[-76.8347266666667,39.213195],
[-76.8345933333333,39.2129983333333],[-76.834455,39.2127816666667],
[-76.8343833333333,39.212615],[-76.834365,39.2125766666667],
[-76.83429,39.2124883333333],[-76.83412,39.21229],[-76.8339066666667,39.2120766666667],
[-76.8337066666667,39.21187],[-76.8336,39.2116516666667],
[-76.8335816666667,39.2114666666667],[-76.8336083333333,39.211325],
[-76.8336516666667,39.2112016666667],[-76.8337066666667,39.21111],
[-76.8337276727651,39.2110803760451],[-76.8337710512136,39.2110192012812],
[-76.8337716666667,39.2110183333333],[-76.8338516666667,39.2109],
[-76.83392,39.2108133333333],[-76.83396,39.2107166666667],
[-76.8339611067922,39.2106613270793],[-76.8339616666667,39.2106333333333],
[-76.833938122743,39.2106129286176],[-76.83389633091,39.2105767090203],
[-76.8338866666667,39.2105683333333],[-76.833715,39.2105016666667],
[-76.833595,39.2104533333333],[-76.83358,39.21045],[-76.833405,39.2103716666667],
[-76.83337,39.210365],[-76.8332116666667,39.2103166666667],[-76.8330966666667,39.21027],
[-76.83299,39.2102233333333],[-76.83286,39.2101766666667],
[-76.8327283333333,39.2101333333333],[-76.8325683333333,39.2100616666667],
[-76.832535,39.2100016666667],[-76.8325183333333,39.2098966666667],
[-76.8325066666667,39.2097333333333],[-76.8324919958592,39.209720248584],
[-76.8323833333333,39.2096233333333],[-76.8321633333333,39.2095333333333],
[-76.8320825997553,39.20948763515],[-76.8319866666667,39.2094333333333],
[-76.8319816666667,39.2092766666667],[-76.83207,39.2091466666667],[-76.832225,39.20905],
[-76.8323483333333,39.2091416666667],[-76.8322416666667,39.2093283333333],
[-76.8321066666667,39.209475],[-76.8320825997553,39.20948763515],
[-76.8319733333333,39.209545],[-76.831862668414,39.20954057341],
[-76.8318483333334,39.20954],[-76.8318415539569,39.2095171966764],
[-76.8318116666667,39.2094166666667],[-76.8318683333333,39.2093033333333],
[-76.8319233333333,39.209195],[-76.8318483333334,39.2091033333333],
[-76.8317466666667,39.2090916666667],[-76.8317216666667,39.209135],
[-76.8317866666667,39.2093583333333],[-76.83182,39.2094933333333],
[-76.8318415539569,39.2095171966764],[-76.831862668414,39.20954057341],
[-76.8319133333333,39.2095966666667],[-76.8318683333333,39.2097],
[-76.8318416666667,39.2097383333333],[-76.8318116666667,39.2098966666667],
[-76.8319366666667,39.2099516666667],[-76.832085,39.21],[-76.83213,39.21008],
[-76.8322416666667,39.2101083333333],[-76.832365,39.2100483333333],
[-76.8324283333333,39.20996],[-76.832475,39.209885],
[-76.83233,39.209355],[-76.8323516666667,39.209475],
[-76.8323933333333,39.2096216666667],[-76.8324924676826,39.2096919391536],
[-76.832525,39.209715],[-76.8326783333333,39.2096816666667],
[-76.8327537674778,39.2096258661087],[-76.8328,39.2095916666667],
[-76.8328766666667,39.2095216666667],[-76.8329,39.20949],
[-76.8328744528093,39.2094841310634],[-76.8327766666667,39.2094616666667],
[-76.8327466666667,39.2095066666667],[-76.832685,39.209635],
[-76.83268,39.2096466666667]] [[[-76.832895,39.20946],
[-76.8328744528093,39.2094841310634],[-76.8327537674778,39.2096258661087],
[-76.8327516666667,39.2096283333333],[-76.8326516666667,39.20973],
[-76.8326416666667,39.2098316666667],[-76.8327033333333,39.2099316666667],
[-76.83284,39.2099916666667],[-76.8329033333333,39.210025],[-76.8331,39.2101616666667],
[-76.8332383333333,39.2102366666667],[-76.8333933333333,39.2103233333333],
[-76.8335416666667,39.2103883333333],[-76.8336783333333,39.21044],
[-76.8338,39.2104816666667],[-76.83389,39.2105533333333],
[-76.83389633091,39.2105767090203],[-76.8339113352774,39.2106321097435],
[-76.8339116666667,39.2106333333333],[-76.8338887881129,39.2106764906686],
[-76.8338383333333,39.2107716666667],[-76.8337783333333,39.2108866666667],
[-76.8337710512136,39.2110192012812],[-76.83377,39.2110383333333],
[-76.8338232468397,39.2111109427531],[-76.83388,39.2111883333333],
[-76.8340466666667,39.2111883333333],[-76.834145,39.211135],
[-76.8341866666667,39.2110433333333],[-76.8342116666667,39.2110016666667],
[-76.83428,39.2108766666667],[-76.8343283333333,39.210795],[-76.83439,39.2107266666667],
[-76.8344492363899,39.2106641394387],[-76.83451,39.2106],[-76.834715,39.21045],
[-76.8349033333333,39.2103033333333],[-76.83497,39.21014],[-76.8349733333333,39.21006],
[-76.834985,39.21022],[-76.834865,39.2104133333333],[-76.83476,39.21059],
[-76.8347916666667,39.21075],[-76.8350466666667,39.2108316666667],
[-76.8352283333333,39.2107116666667],[-76.83532,39.2105266666667],
[-76.8354483333333,39.2103633333333],[-76.83555,39.21017],
[-76.8356666666667,39.2100466666667],[-76.8358216666667,39.21004],
[-76.8358733333333,39.2101316666667],[-76.8358316666667,39.2102883333333],
[-76.8359,39.210425],[-76.8358689842204,39.2104852071477],[-76.8358433333333,39.210535],
[-76.8356983333333,39.210565],[-76.8357383333333,39.210475],
[-76.8358689842204,39.2104852071477],[-76.8359516666667,39.2104916666667],
[-76.8360516666667,39.210455],[-76.8361533333333,39.2102916666667],
[-76.836285,39.210175],[-76.8364766666667,39.21023],[-76.8366683333333,39.21028],
[-76.8368166666667,39.210305],[-76.836955,39.2103233333333],
[-76.83699,39.2103183333333],[-76.8373016666667,39.2103166666667],
[-76.8374566666667,39.2103016666667],[-76.8376066666667,39.21029],
[-76.8377616666667,39.2103016666667],[-76.83795,39.210335],
[-76.8381333333333,39.2104033333333],[-76.83831,39.2105133333333],
[-76.8384333333333,39.2106416666667],[-76.8385183333333,39.210785],
[-76.8385616666667,39.210935],[-76.838585,39.2110366666667],
[-76.8386083333334,39.2111266666667],[-76.83865,39.211245],
[-76.8387166666667,39.211505],[-76.838855,39.2116916666667],
[-76.839035,39.2118216666667],[-76.8392,39.2119766666667],[-76.8393516666667,39.212125],
[-76.83948,39.21218],[-76.8395733333333,39.2121633333333],
[-76.8398377180994,39.212155736099],[-76.839863333316,39.2121550000005],
[-76.8398633333333,39.212155],[-76.839866248213,39.2121550000002],
[-76.8398683333333,39.212155],[-76.839885,39.212155],
[-76.839863333316,39.2121550000005],[-76.83984,39.212155],
[-76.8398377180994,39.212155736099],[-76.839685,39.212205],
[-76.8395033333333,39.212245],[-76.83924,39.2121616666667],
[-76.8390316666667,39.2119483333333],[-76.8388216666667,39.2117766666667],
[-76.8387066666667,39.21161],[-76.838545,39.21148],[-76.8383866666667,39.211435],
[-76.8381966666667,39.2114216666667],[-76.8380266666667,39.21142],
[-76.8378533333333,39.2114133333333],[-76.8376933333333,39.2114116666667],
[-76.837545,39.2113983333333],[-76.837365,39.2114166666667],
[-76.837145,39.2113883333333],[-76.83696,39.2113683333333],[-76.8368116666667,39.21135],
[-76.8366616666667,39.211345],[-76.8365166666667,39.21134],
[-76.836395,39.2113383333333],[-76.83635,39.21134],[-76.8361416666667,39.21133],
[-76.8359466666667,39.2112916666667],[-76.8358183333333,39.2112233333333],
[-76.8357733333333,39.2111683333333],[-76.8357366666667,39.211055],
[-76.8356816666667,39.2109716666667],[-76.83552,39.211005],
[-76.8353483333333,39.2109983333333],[-76.8351966666667,39.2109416666667],
[-76.835055,39.210885],[-76.8349033333333,39.21081],[-76.83475,39.2107766666667],
[-76.834625,39.2107333333333],[-76.83449,39.2106866666667],
[-76.8344492363899,39.2106641394387],[-76.8343633333333,39.2106166666667],
[-76.834205,39.21054],[-76.8340283333333,39.2105483333333],
[-76.833938122743,39.2106129286176],[-76.8339113352774,39.2106321097435],
[-76.8338933333333,39.210645],[-76.8338216666667,39.2107666666667],
[-76.83377,39.2108516666667],[-76.8337333333333,39.2109116666667],
[-76.8337122666612,39.2109696000596],[-76.8336933333333,39.2110216666667],
[-76.8337276727651,39.2110803760451],[-76.833745,39.21111],
[-76.8338232468397,39.2111109427531],[-76.8338833333333,39.2111116666667],
[-76.83392,39.211055],[-76.8339716666667,39.2109833333333],
[-76.8340783333333,39.2108283333333],[-76.8340766666667,39.210725],
[-76.8339833333333,39.2106566666667],[-76.8339611067922,39.2106613270793],
[-76.8338887881129,39.2106764906686],[-76.83388,39.2106783333333],
[-76.8338083333333,39.2108016666667],[-76.83373,39.2109366666667],
[-76.8337122666612,39.2109696000596],[-76.83366,39.2110666666667],
[-76.8335933333333,39.21119],[-76.8335266666667,39.211375],[-76.83353,39.2116183333333],
[-76.833635,39.2118683333333],[-76.8338283333333,39.212085],
[-76.8340583333333,39.2123116666667],[-76.8342483333333,39.21253],[-76.834345,39.21274],
[-76.8344233333333,39.212935],[-76.8343933333333,39.21316],
[-76.8345383333333,39.2133166666667],[-76.8347266666667,39.213195],
[-76.8345933333333,39.2129983333333],[-76.834455,39.2127816666667],
[-76.8343833333333,39.212615],[-76.834365,39.2125766666667],
[-76.83429,39.2124883333333],[-76.83412,39.21229],[-76.8339066666667,39.2120766666667],
[-76.8337066666667,39.21187],[-76.8336,39.2116516666667],
[-76.8335816666667,39.2114666666667],[-76.8336083333333,39.211325],
[-76.8336516666667,39.2112016666667],[-76.8337066666667,39.21111],
[-76.8337276727651,39.2110803760451],[-76.8337710512136,39.2110192012812],
[-76.8337716666667,39.2110183333333],[-76.8338516666667,39.2109],
[-76.83392,39.2108133333333],[-76.83396,39.2107166666667],
[-76.8339611067922,39.2106613270793],[-76.8339616666667,39.2106333333333],
[-76.833938122743,39.2106129286176],[-76.83389633091,39.2105767090203],
[-76.8338866666667,39.2105683333333],[-76.833715,39.2105016666667],
[-76.833595,39.2104533333333],[-76.83358,39.21045],[-76.833405,39.2103716666667],
[-76.83337,39.210365],[-76.8332116666667,39.2103166666667],[-76.8330966666667,39.21027],
[-76.83299,39.2102233333333],[-76.83286,39.2101766666667],
[-76.8327283333333,39.2101333333333],[-76.8325683333333,39.2100616666667],
[-76.832535,39.2100016666667],[-76.8325183333333,39.2098966666667],
[-76.8325066666667,39.2097333333333],[-76.8324919958592,39.209720248584],
[-76.8323833333333,39.2096233333333],[-76.8321633333333,39.2095333333333],
[-76.8320825997553,39.20948763515],[-76.8319866666667,39.2094333333333],
[-76.8319816666667,39.2092766666667],[-76.83207,39.2091466666667],[-76.832225,39.20905],
[-76.8323483333333,39.2091416666667],[-76.8322416666667,39.2093283333333],
[-76.8321066666667,39.209475],[-76.8320825997553,39.20948763515],
[-76.8319733333333,39.209545],[-76.831862668414,39.20954057341],
[-76.8318483333334,39.20954],[-76.8318415539569,39.2095171966764],
[-76.8318116666667,39.2094166666667],[-76.8318683333333,39.2093033333333],
[-76.8319233333333,39.209195],[-76.8318483333334,39.2091033333333],
[-76.8317466666667,39.2090916666667],[-76.8317216666667,39.209135],
[-76.8317866666667,39.2093583333333],[-76.83182,39.2094933333333],
[-76.8318415539569,39.2095171966764],[-76.831862668414,39.20954057341],
[-76.8319133333333,39.2095966666667],[-76.8318683333333,39.2097],
[-76.8318416666667,39.2097383333333],[-76.8318116666667,39.2098966666667],
[-76.8319366666667,39.2099516666667],[-76.832085,39.21],[-76.83213,39.21008],
[-76.8322416666667,39.2101083333333],[-76.832365,39.2100483333333],
[-76.8324283333333,39.20996],[-76.832475,39.209885],[-76.83249,39.20984],
[-76.8324919958592,39.209720248584],[-76.8324924676826,39.2096919391536],
[-76.8324933333333,39.20964],[-76.8325983333333,39.2094983333333],
[-76.8326833333333,39.2093466666667],[-76.83268,39.2091916666667],
[-76.8324833333333,39.2091266666667],[-76.8323283333333,39.2092133333333],
[-76.83233,39.209355],[-76.8323516666667,39.209475],
[-76.8323933333333,39.2096216666667],[-76.8324924676826,39.2096919391536],
[-76.832525,39.209715],[-76.8326783333333,39.2096816666667],
[-76.8327537674778,39.2096258661087],[-76.8328,39.2095916666667],
[-76.8328766666667,39.2095216666667],[-76.8329,39.20949],
[-76.8328744528093,39.2094841310634],[-76.8327766666667,39.2094616666667],
[-76.8327466666667,39.2095066666667],[-76.832685,39.209635],
[-76.83268,39.2096466666667]]]
ok found the answer, will put it here in case some one else has the same issue.
the trick is to do nested replace instead separate ones. just change this line
select * from(
(select replace(substring(geo,1),"[[[", "[[") as ngeo union
DISTINCT
(select replace
(substring(geo,1),"]]]", "]]")) union DISTINCT select replace
(substring(geo,1),"]],[[" ,"], ["))
with
select replace(replace(replace(substring(geo,1),"[[[", "[["),"]]]",
"]]"),"]],[[" ,"],[" ) as ngeo

SQL replace function error while using it to replace one string

I have event table in which there are two fields named as sport, event_name .
This was values such as:
{sport:"Athletic"; event_name:"Athletic 100 meter"}
What I want is to use replace function to replace the string in event_name that matches string in sport with nothing.
so the final output will be such :
{sport:"Athletic"; event_name:"100 meter"}
And I was also joined it with other table so only ID that are to be replace are also present in other table
so I used in this way in following code. But it should an error : "Expected item: < result-column > " . Thank you
SELECT
ae.id ,
ae.city AS event_city,
ae.sport,
REPLACE(ae.event,ae.sport,' ') AS event_name ,
FROM
athlete_events ae
inner join
players_personalinfo pp on
pp.id=ae.id
You need to define the table aliases:
SELECT ae.id AS event_id, ae.city AS event_city, ae.sport,
REPLACE(ae.event, ae.sport, ' ') AS event_name ,
ae.event
FROM athlete_events ae JOIN
players_personalinfo pp
ON pp.id = ae.id;
I would also advise you to trim the result:
TRIM(REPLACE(ae.event, ae.sport, ' ')) AS event_name,
This will remove leading and trailing spaces.
The REPLACE function is case sensitive. Try to check the data to make sure that the capitalization of each is the same.
The prior answers work, but you need to modify one of the field names in your query. In your description, you mentioned the field name is "event_name", but in your query, you reference just "event" (ae.event).
Also, I'm a little surprised that an event_id would join to a player's profile id. Seems a bit odd.
At any rate, I confirmed this SQL works in both postgres and oracle databases...
SELECT
ae.id AS event_id,
ae.city AS event_city,
ae.sport,
ae.event_name as event_name_original
REPLACE(ae.event_name,ae.sport,' ') AS event_name_kinda_ugly,
TRIM(REPLACE(ae.event_name,ae.sport,' ')) AS event_name_clean
FROM
athlete_events ae
inner join
players_personalinfo pp on pp.id=ae.id

Postgresql : How to update one field for all duplicate values based at the end of the string of a field except one row

http://sqlfiddle.com/#!9/b98ea/1 (Sample Table)
I have a table with the following fields:
transfer_id
src_path
DH_USER_ID
email
status_state
ip_address
src_path field contains a couple of duplicates filename values but a different folder name at the beginning of the string.
Example:
191915/NequeVestibulumEget.mp3
/191918/NequeVestibulumEget.mp3
191920/NequeVestibulumEget.mp3
I am trying to do the following:
Set status_state field to 'canceled' for all the duplicate filenames within (src_path) field except for one.
I want the results to look like this:
http://sqlfiddle.com/#!9/5e65f/2
*I apologize in advance for being a complete noob, but I am taking SQL at college and I need help.
SQL Fiddle Demo
fix_os_name: Fix the windows path string to unix format.
file_name: Split the path using /, and use char_length to bring last split.
drank: Create a seq for each filename. So unique filename only have 1, but dup also have 2,3 ...
UPDATE: check if that row have rn > 1 mean is a dup.
.
Take note the color highlight is wrong, but code runs ok.
with fix_os_name as (
SELECT transfer_id, replace(src_path,'\','/') src_path,
DH_USER_ID, email, status_state, ip_address
FROM priority_transfer p
),
file_name as (
SELECT
fon.*,
split_part(src_path,
'/',
char_length(src_path) - char_length(replace(src_path,'/','')) + 1
) sfile
FROM fix_os_name fon
),
drank as (
SELECT
f.*,
row_number() over (partition by sfile order by sfile) rn
from file_name f
)
UPDATE priority_transfer p
SET status_state = 'canceled'
WHERE EXISTS ( SELECT *
FROM drank d
WHERE d.transfer_id = p.transfer_id
AND d.rn > 1);
ADD: One row is untouch
Use the regexp_matches function to separate the file name from the directory.
From there you can use distinct() to build a table with unique values for the filename.
select
regexp_matches(src_path, '[a-zA-Z.0-9]*$') , *
from priority_transfer
;