Update Field Geometry Polygon PostGIS PostgreSQL - sql

I am having some trouble trying to update a field.
I created a column as text and stored many rows with (lon,lat). Now I have created one more field as Geometry(Polygon) and I am trying to update it unsuccessfully.
The data is stored like this:
POLYGON ((-16.6318775869111 -52.5925428149806, -16.6346393504709 -52.572542814981
, -16.629462102066 -52.5525428149806, -16.6255191065928 -52.5455420519144
, -16.6055191065928 -52.5488828022871, -16.6021791014778 -52.552542814981
, -16.6108484688169 -52.5925428149806, -16.6255191065928 -52.599495926874
, -16.6318775869111 -52.5925428149806))
I am trying this command
UPDATE field_as_text
SET field_as_geomtry = SELECT ST_GeomFromText(SELECT field_as_text);
I am getting this error message
ERROR: syntax error at or near "select"
LINE 1: ... set field_as_geomtry = select (ST...
Could anyone enlighten me?

You need to start by reading the manual about the SQL UPDATE command.
Should look something like this:
UPDATE table_name
SET field_as_geomtry = ST_GeomFromText(field_as_text);

Related

How to determine the column with multiple items of data has one specified value in BigQuery?

This is my table:
I want to change the TargetCondition column to 'TRUE' when the ICD9CODE column contains a particular range (like between 250 and 250.93).
Please help me do it. Thanks
This is the code here:
update demo.fea_02 set TargetCondition = TRUE where ICD9Code like between '%250%' and '%250.93%'
got the error:
Syntax error: Unexpected keyword BETWEEN at [6:17]
This answers the original version of the question.
You would use update:
update mytable
set targetcondition = 'TRUE'
where icd9code like '%value%';

REPLACE statement produces "Data truncation" error. Please advise why and how to correct it

UPDATE ASSIGNMENTS SET CBTURL = REPLACE(CBTURL, 'http://172.21.130.19/', 'https://testlpsweb.corp.mbll.ca/Content/')
The above statement produces "Data truncation" error. Please advise why and how to correct it.
Error starting at line : 1 in command - UPDATE ASSIGNMENTS SET CBTURL = REPLACE(CBTURL, 'http://172.21.130.19/', 'https://testlpsweb.corp.mbll.ca/Content/') Error at Command Line : 1 Column : 1 Error report - SQL Error: Data truncation
I'm guessing that CBTURL column length is to small for resulting string of replace. Could you try to alter column to have larger lenght.
Try this query to see maximum resulst string lenght:
Select Max(Len(REPLACE(CBTURL, 'http://172.21.130.19/', 'https://testlpsweb.corp.mbll.ca/Content/'))) from tablename ....

PostgreSQL JSON SQL Update Statement

I am testing out how JSON works in PostgreSQL 9.4 and I'm finding it to be really cool so far.
I'm stuck on one part though. I'm hoping it is possible to run a SQL UPDATE statement on JSON data.
What I was trying to see if I could do was have a Nested Set inside JSON data and Update the left and right when I add a comment.
My query is:
UPDATE
comments
SET
comment #>> '{right}' += 2
WHERE
comment #>> '{post_id}' = '{$input['post_id']}'
AND comment#>>'{right}' >= '{$parent->right}'
I do get an error:
Syntax error: 7 ERROR: syntax error at or near "#>>"
LINE 5: comment#>>'{right}' += 2
I've not been able to find a resource that tells me if it's possible to update an item inside the JSON.
Thank you
Updating JSON Data
If the column in your table contains json data and you want to update this data, you can use the following structure:
UPDATE table_name SET column_name = '{"key" : value}'::jsonb
WHERE column_name::jsonb #> '{“new_key” : new_value}'::jsonb;
Note: Usually #> is used as the "contains" operator.

Update date within a table, Postgresql

So I'm having trouble understanding on how to change the date on an update in postgres. What I have currently, that is giving a syntax error is
UPDATE works_locations SET (wrl_startdate = '2014-09-07', wrl_enddate = '2015-02-06')
with a few statements determining which field I should specifically change. However, postgres is giving me an error. How do I successfully change the date in postgres, even if the start date is around two years prior to this entry?
I don't have Postgres installed so I can't test this but try removing the parenthesis on your SET clause so that it looks like this:
UPDATE works_locations SET wrl_startdate = '2014-09-07', wrl_enddate = '2015-02-06'

Rename SQL Server 2005 Row Values

I want to rename several values on my table.
I just want to rename multi rows in a column of a table in my database :
SJ.10.06.000001
SJ.10.06.000002
SJ.10.06.000003
SA.10.06.000001
SB.10.06.000002
etc into this value :
SJ.09.06.000001
SJ.09.06.000002
SJ.09.06.000003
SA.09.06.000001
SB.09.06.000002
My SQL :
Update dbo.Deposito
set nomor sj.09...
where no rekening sj.10...
and I've got this :
Update dbo.Deposito
set nomor sj.09...
where no rekening sj.10...
Error
[Err] 42000 - [SQL Server]Incorrect syntax near 'sj'.
try this....
UPDATE dbo.Deposito
SET nomor = REPLACE(nomor, '.10.', '.09.')
WHERE SUBSTRING(nomor, 4, 2) = '10'
I think you can do this with substring too, but I could not remember the correct syntax, so I think you should try this.
It updates the values based on the 3rd and 4th characters in your table, so it exchanges 10 to 9, if that's what you are after.
There are a lot of ways to achieve this, it's just one of them.
update
I have tested this locally and it works.
UPDATE
dbo.Deposito
SET
nomor = REPLACE(nomor,'.10.','.09.')
WHERE
substring(nomor,4,2) = '10'