I currently have a very simple select that my code then dumps into JSON
SELECT user, phone
FROM table t;
But the select returns all uppercase column names, resulting in uppercase JSON keys, which I don't want. Is there a way in DB2 to return lowercase column names?
If you want to get lowercase columns names (not data) in DB2, you must use double quotes around the column names.
SELECT user as "user", phone as "phone"
FROM table t;
If you want the result of the query to be small, try this
SELECT LOWER(user), LOWER(phone)
FROM table t;
Use the LOWER() function;
SELECT LOWER(user) AS 'user', LOWER(phone) AS 'phone'
FROM table t;
Related
What query could I use in sqlite to get the names of columns beginning with (for example) "thing" in a DB
Such as if they were formatted like this:
"thing_column1"
"thing_column2"
"thing_data"
etc.
You can use pragma_table_info() with the table's name:
SELECT name
FROM pragma_table_info('tablename')
WHERE name LIKE 'thing%'
You can use this query:
SELECT GROUP_CONCAT(name) AS columns
FROM pragma_table_info('tablename')
WHERE name LIKE 'thing%'
which returns only 1 column columns with a string value like 'thing_column1,thing_column2,thing_column3' and you can use it to construct a SELECT statement in your application.
I have a table called table with column called column with datatype text with values like '["1","2"]'.
I need to get all records which has "1" as one of the element.
select *
from table
where column.....?
How should the where clause be?
Simply use LIKE. Keep the double quotes to pass 1, but avoid other numbers containing that digit.
select *
from table
where column like '%"1"%'
I think you can use ? operator on jsonb type:
select *
from (
select '["1","2"]' union all
select '["0"]'
) as a(data)
where
a.data::jsonb ? '1'
In general, I'd consider storing your data as jsonb instead of string.
db<>fiddle example
I just try use
SELECT UPPER(*) FROM TABLE
but it didn't work
I suggest use the sentence UPPER for each varchar or char field in your table.
For example:
SELECT UPPER(Name), UPPER(LastName), UPPER(CityName) FROM ClientsTable
On this way you obtain the data in uppercase.
I am trying to run few queries on Oracle SQL developer
e.g
Select name AS CandidateName, age AS CandidateAge
from tbl_candidate_details
order by candidate_id desc
But In the result I am getting the column names as "CANDIDATENAME" AND "CANDIDATEAGE".
Is there a way where I can get this as camelcase characters what I have given in the select statement("CandidateName" and "CandidateAge") ?
If the column aliases are wrapped in double-quotes, SQL Developer will use those exact values as the column names in the query results:
SELECT name AS "CandidateName", age AS "CandidateAge"
FROM tbl_candidate_details
ORDER BY candidate_id DESC;
Otherwise, the column names in the query results are always displayed in upper case
SQL is case insensitive and the SQL standard requires to fold all un-quoted identifiers to uppercase. If you want to preserve the case of your identifiers you need to quote them:
Select name AS "CandidateName",
age AS "CandidateAge"
from tbl_candidate_details
order by candidate_id desc
Here's my SQLite table (in comma-delimited format):
ROWID,COLUMN
1,"This here is a string |||"
2,"Here is another string"
3,"And yet another string"
I want to exclude all rows under 'COLUMN' which contain '|||'. Is this possible in SQLite?
select * from table where column not like '%|||%'
this should work
select * from your_table
where your_column not like '%'|||%'
SQLFiddle demo