I use the query below:
update ACCOUNT_EXTERNAL_IDS
set EXTERNAL_ID = 'username:vietnt'
where ACCOUNT_ID='1000000'
and EMAIL_ADDRESS='NULL'
It shows the error:
ERROR: Column "USERNAME" not found; SQL statement:
update ACCOUNT_EXTERNAL_IDS set EXTERNAL_ID=username:vietnt where ACCOUNT_ID=1000000 and EMAIL_ADDRESS=NULL [42122-147]
I use back slash \, then, the query become:
update ACCOUNT_EXTERNAL_IDS
set EXTERNAL_ID = 'username\:vietnt'
where ACCOUNT_ID = '1000000'
and EMAIL_ADDRESS='NULL'
The error is the same.
Resolved!
The escape character '\' resolve the problem.
The issue I encounter is I use ssh connect. So, it eliminates the character '\'
Related
I set a variable name for a table as lowercase:
Set TGT_TABLE = 'tab_name';
however when i try to call it:
select * from table($TGT_TABLE);
I get an error:
SQL compilation error: Object 'TAB_NAME' does not exist or not authorized.
Why is it calling the uppercase version of my table name
Also I veriefied in the 'show variables' that my variable is indeed lowercase
in order to use lower case identifiers, these must be in double-quotes. in order to assign it to a variable, this must additionally be in single quotes.
#jarlh 's answer is correct, note the single quotes surrounding the double quotes.
Set TGT_TABLE = '"tab_name"';
select * from table($TGT_TABLE);
if in doubt, copy/ paste
You can Write Your Code Like This :
declare #TGT_TABLE nvarchar(50),#query nvarchar(50)
Set #TGT_TABLE = 'name of your table';
SET #query = 'SELECT * FROM ' + #TGT_TABLE;
EXEC(#query);
It will worked.
I'm coming from SQL Server and I was suprised to see that the following query does not work:
DELETE FROM user_job_titles WHERE id IN (
"c836d018-1d12-4507-a268-a4d80d6d3f54",
"d0961a90-7d31-4c4c-9c1b-671115e3d833",
"62dda420-6e62-4017-b41d-205c0aa82ead"
)
where user_job_titles has the following columns:
id
user_id
job_title_id
The error is:
ERROR: column "c836d018-1d12-4507-a268-a4d80d6d3f54" does not exist
LINE 2: "c836d018-1d12-4507-a268-a4d80d6d3f54"
I'm using pgAdmin with latest postgresql version. Is there any other way to run this query?
Use single quotes for string constants:
DELETE FROM user_job_titles
WHERE id IN ('c836d018-1d12-4507-a268-a4d80d6d3f54',
'd0961a90-7d31-4c4c-9c1b-671115e3d833',
'62dda420-6e62-4017-b41d-205c0aa82ead'
);
Double quotes are an escape character used with table and column names. Hence the error.
You need to quote string literals with '
DELETE FROM user_job_titles
WHERE id IN (
'c836d018-1d12-4507-a268-a4d80d6d3f54',
'd0961a90-7d31-4c4c-9c1b-671115e3d833',
'62dda420-6e62-4017-b41d-205c0aa82ead'
);
I'm coming from SQL Server and I was suprised to see that the following query does not work
Then you have SET QUOTED_IDENTIFIER AS OFF. By default it is ON.
When SET QUOTED_IDENTIFIER is ON, all strings delimited by double
quotation marks are interpreted as object identifiers.
Check:
SET QUOTED_IDENTIFIER OFF;
SELECT "A"
-- The same behaviour as in Postgresql
SET QUOTED_IDENTIFIER ON;
SELECT "A"
-- Invalid column name 'A'.
LiveDemo
I come from MySQL and the below query doesn't work in Sybase. How should I escape single quotes?
UPDATE Animals SET NAME = 'Dog\'s friends' WHERE uid = 12
If working with Sybase, having got used to MySQL which more database users have experience you may soon discover you are unable to escape single quotes with backslash in.
So how do you escape quotes in Sybase? In fact, in Sybase SQL the single quote acts as the escape character.
See below for an example UPDATE statement in both “languages”:
MySQL
UPDATE Animals SET NAME = 'Dog\'s friends' WHERE uid = 12
Sybase
UPDATE Animals SET NAME = 'Dog''s friends' WHERE uid = 12
I’m not entirely sure this makes sense to me (especially as it looks like a double quote) but there you go!
You can create a custom function to escape quotes :
CREATE FUNCTION "ESCAPE_QUOTES"(in a_string long varchar)
returns long varchar
begin
return replace(a_string, '''', '''''');
end
I am trying to run a query like
UPDATE myTable SET Name='B&L' WHERE ID = 1;
The problem is I am getting the following error:
Unclosed quotation mark after the character string 'B'.
My column is of type varChar and as you can see I am escaping the string with 'quotes'. How can I get the & symbol to insert?
Thanks.
For MSSQL try escaping the & by enclosing it in square brackets so it would become:
UPDATE myTable SET Name='B[&]L' WHERE ID = 1;
Or you could use the ESCAPE statment like so:
UPDATE myTable SET Name='B\&L' WHERE ID = 1 ESCAPE '\';
It seems like your statement should work in SQL Server. I saw some instances of Oracle that had issues with ampersands. In those cases, you could use something like this:
UPDATE myTable SET Name='B&' + 'L' WHERE ID = 1
I need to find records containing html code such as ' ' But when I try to run the select * from table_name where column like ' %'
I got prompt asking for the value of nbsp. I guess the database thinks that nbsp is a parameter. I am wondering if the is an escape character so that I can tell the database that "&" is part of my query string. I tryed '\ ' but didn't work.
My environment is Oracle 9i with sqlplus client.
Thanks.
Have a look at this:
SQL Plus FAQ
e.g.
SET ESCAPE '\'
SELECT '\&abc' FROM dual;
Easier way:
SET DEFINE OFF
See:
SET DEFINE
The backslash should work, but I think you need to start your query with
SET ESCAPE ON
In PL/SQL, you would use:
BEGIN select <Column> from <Table_name> into <Variable> where <Column> LIKE '\ \%' ESCAPE '\'; END
/
Resources:
Wilcards in SQL on PSOUG.org
LIKE Condition in Oracle® Database SQL Language Reference 11g Release 2 (11.2)