Postgresql : Search field contain tab character. (With LIKE) - postgresql

I'm searching how to check if any field contains the TAB character.
after read this post, I tried to use this command :
SELECT id FROM account WHERE description LIKE '%\t%';
But it returns me all fields that contain the 't' character.
Do you have any solution to represent the TAB character ?

In SQL there is no "escaping" of characters like \t. You can use the chr() function for this:
select id
from account
where description LIKE '%'||chr(9)||'%'
I prefer the strpos function in this case, because I think it makes the intention clearer
select id
from account
where strpos(description, chr(9)) > 0

you have to use a literal tab chacater,
SELECT id FROM account WHERE description LIKE '% %';
In psql type ctrl-V and then TAB to enter a tab. in other environments there are other ways to enter literal tabs.
Alternatively you can use escape string syntax: e'%\t%', or octal escape e'%\011%'.

I'm very late to this party, but having looked into this today, I've found you can also use regular expression.
SELECT id FROM account WHERE description ~ '\t';

Related

How to enter in a unicode character code in BigQuery?

Let's say I want to use the character 倀:
https://www.fileformat.info/info/unicode/char/20480/index.htm
How would I type this into a query in BigQuery with the proper escape sequence? My thought was the following, but this seems like it's not correct based on the Lexical Structure:
SELECT '倀', '\U00020480'
But obviously that's not correct as I'm getting:
How would I properly type it in with the escape code?
Consider below "hint"
SELECT '倀', CODE_POINTS_TO_STRING([00020480])
with output

T-SQL Procedure parameter name

I have to create a procedure with same parameters names as excel columns. Some loook like this 'xxx/xxx' or 'xxx - xxx'. Is there any work around to name parameteres in a stored procedure like this?
Forward slash (/) or dash (-) are not allowed in variable names
According to http://msdn.microsoft.com/en-us/library/ms175874.aspx, that means that the allowed characters are:
Letters as defined in the Unicode Standard 3.2. The Unicode
definition of letters includes Latin characters from a through z,
from A through Z, and also letter characters from other languages.
Decimal numbers from either Basic Latin or other national scripts.
The at sign (#), dollar sign ($), number sign (#), or underscore (_).
Okay first of all why would you ever want to use special characters? That is like saying I want to fry toast underwater with electricity, why can't I have an outlet to allow that? Special characters denote special things and as such many engines, not just in SQL, but most languages will not allow reserved characters for use in variables. The best you could do was put in parameters with the reversed '_' and then replace that AFTER the object was already created for echoing out. The placeholder name of '#(something)' is really arbitrary and could be #X or #LookAtMe. It's type is important to form a contract that must be fulfilled for execution but the naming is really for hooking up. Having said that if you just must have these weird names echoed out you could do something like this:
CREATE PROC pSimpleParam #My_Param INT
AS
SELECT #My_Param
GO
ALTER PROC pSimpleParam #My_Param INT
AS
SELECT
pr.name AS ParameterName
, REPLACE(pr.name, '_', '-') AS AlteredParameterName
FROM sys.procedures p
INNER JOIN sys.parameters pr ON pr.object_id = p.object_id
AND p.name = 'pSimpleParam'
GO

How to select a word in a text SQL query?

On our PostgreSQL Database we have a field called Description. As you can guess this Description contains a lot of text and we would like to look inside this descriptions to find a certain word.
We tried contains and Charindex function but both are not working...
Any Idea how we can solve this?
Thank you very much!
Luca
You can use regular expressions with word delimiter markers:
select * from table
where description ~ ('\m' || 'yourword' || '\M');
Use ~* instead of ~ for case insensitive searches.
Note that using description LIKE '%yourword%' as #JNevill suggests will find that your word within other words as well, e.g. 'Jean-Luc Picard' LIKE '%car%' is true.

PostgreSQL - how to drop a user with hyphen in his username

I can't seem to execute DROP USER username if the username contains hyphens (-), like for example user-name.
I tried a straightforward DROP USER user-name, also DROP USER 'user-name' but I'm getting: ERROR: syntax error at or near "'user-name'".
I would guess I need to use some kind of escaping or something.
Identifiers need to be quoted using double quotes, single quotes are for string literals:
DROP USER "user-name";
More details in the manual: http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

Find all references to a specific table column in Oracle (10g) [duplicate]

Is there a query I can run to search all packages to see if a particular table and/or column is used in the package? There are too many packages to open each one and do a find on the value(s) I'm looking for.
You can do this:
select *
from user_source
where upper(text) like upper('%SOMETEXT%');
Alternatively, SQL Developer has a built-in report to do this under:
View > Reports > Data Dictionary Reports > PLSQL > Search Source Code
The 11G docs for USER_SOURCE are here
you can use the views *_DEPENDENCIES, for example:
SELECT owner, NAME
FROM dba_dependencies
WHERE referenced_owner = :table_owner
AND referenced_name = :table_name
AND TYPE IN ('PACKAGE', 'PACKAGE BODY')
Sometimes the column you are looking for may be part of the name of many other things that you are not interested in.
For example I was recently looking for a column called "BQR", which also forms part of many other columns such as "BQR_OWNER", "PROP_BQR", etc.
So I would like to have the checkbox that word processors have to indicate "Whole words only".
Unfortunately LIKE has no such functionality, but REGEXP_LIKE can help.
SELECT *
FROM user_source
WHERE regexp_like(text, '(\s|\.|,|^)bqr(\s|,|$)');
This is the regular expression to find this column and exclude the other columns with "BQR" as part of the name:
(\s|\.|,|^)bqr(\s|,|$)
The regular expression matches white-space (\s), or (|) period (.), or (|) comma (,), or (|) start-of-line (^), followed by "bqr", followed by white-space, comma or end-of-line ($).
By the way, if you need to add other characters such as "(" or ")" because the column may be used as "UPPER(bqr)", then those options can be added to the lists of before and after characters.
(\s|\(|\.|,|^)bqr(\s|,|\)|$)