This question already has answers here:
String concatenation does not work in SQLite
(4 answers)
Closed 9 months ago.
I'm using this to try and name the values in NAME to ValueOLD
UPDATE PLAYERS SET NAME = NAME + 'OLD';
However I am receiving
Execution finished with errors.
Result: UNIQUE constraint failed: PLAYERS.NAME
At line 1:
UPDATE PLAYERS SET NAME = NAME + 'OLD';
I've seen some questions asked on inserts that look like they work, but haven't had any success with UPDATE or SET
In SQLite, || can be used for concatenation.
So Try:
UPDATE
PLAYERS
SET
NAME = NAME || 'OLD';
SQL Language Expressions
The || operator is "concatenate" - it joins together the two strings
of its operands.
Related
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 2 years ago.
I have to find a table name from a query dynamically. The table name in the query may or may not be preceded by the schema name. But the table name will always be followed by a "#dblink" string.
The query pattern is like : 'select c1, c2 from schema.table_name#dblink ...'
Or, it could be like : 'select c1,c2,c3 from table_name#dblink ...'
That is, the number of columns - c1, c2 etc - are variable. Also, the developers can probably put in multiple consecutive spaces anywhere between any 2 words.
My objective is to retrieve the name of the table "table_name".
How can I do this using regular expression ?
If you want the word that preceds '#dblink', you can do:
regexp_replace(mycol, '.*\W(\w+)#dblink.*', '\1')
declare var
SELECT name into var from table where name LIKE '%#dblink';
You can print like this
DBMS_OUTPUT.PUT_LINE (var);
This question already has an answer here:
Strange behaviour in Postgresql
(1 answer)
Closed 6 years ago.
select * from note where noteKey = 1
This statement gives me the following error.
ERROR: column "notekey" does not exist
LINE 1: select * from note where noteKey = 1
^
HINT: Perhaps you meant to reference the column "note.noteKey".
I tried note.noteKey, but got the same error. (I used postico by the way, and the noteKey is the primary key of the table note).
What could possibly be wrong with the statement?
You need to connect with psql and run \d note.
If that shows the column is called noteKey with an uppercase K then you either have two options
Rename the column ALTER TABLE note RENAME COLUMN "noteKey" TO notekey;
Forever use double quotes " to query it.
In PostgreSQL we never quote column names. This forces them to be caps sensitive. When not quoted, they're automatically lower cased.
This
select * from note where noteKey = 1
Is the same as
select * from note where notekey = 1
Which is different from
select * from note where "noteKey" = 1
This question already has answers here:
Insert text with single quotes in PostgreSQL
(8 answers)
Closed 3 years ago.
so I am trying to run a script like this one:
select id
from owner
where owner.name = "john's"
and I am getting this error: ERROR: column "john's" does not exist.
Also I tried like this: where owner.name = 'john\'s', but it dit not work
Anyone knows how I can run a query like this one?
You can escape single quotes when you double them.
For example:
= 'john''s'
Try this
select id
from owner
where owner.name = (E'john\'s')::text
Update:
we can escape most of the characters using this statement
select id
from owner
where owner.name = (E'john\character you want to escape's')::text
This question already has answers here:
Oracle SQL, concatenate multiple columns + add text
(6 answers)
Closed 7 years ago.
when I run the below query
select concat(column1,column2,column3) as concatcolumn from table
I get an error "ORA-00909:INVALID NUMBER OF ARGUMENTS"
Concat only takes two arguments.
See: http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions026.htm
Use the concatenation operator:
select column1 || column2 || column3 ...
select ([column1]+','+[column2]+','+[column3]) as concatcolumn from table
Try above the query.it may changes on different type of column data type.
This question already has answers here:
SQL UPDATE SET one column to be equal to a value in a related table referenced by a different column?
(12 answers)
Closed 9 years ago.
I have a database with email addresses in it.
My company is changing our email address convention from:
first_initiallast_name#mycompany.com
to
first_name.last_name#contoso.com
I'd like to write a SQL statement to update all the email addresses in one shot in this database. First and last name are columns in the same table (we'll call it MY_TABLE for simplicity's sake).
How could I do this in an Oracle SQL statement?
It seems like you'd just want
UPDATE my_table
SET email_address = first_name || '.' || last_name || '#contoso.com'
That will update every row in the table and assumes that you have no NULL first or last name values.
You juste want to update the email field with two others fields:
UPDATE my_table SET email= first_name || '.' || last_name || '#contoso.com'
WHERE first_name != NULL AND last_name != NULL
Be aware that the transformation might be incorrect if first_name or last_name is empty...
EDIT: In reality what you want is similar to this question: SQL UPDATE SET one column to be equal to a value in a related table referenced by a different column?