How can I query in psql. If column name like camelCase [duplicate] - postgresql

This question already has answers here:
Are PostgreSQL column names case-sensitive?
(5 answers)
Closed 5 years ago.
My psql table structure like below:
id userName gender
1 xxxx Male
if I am using query like below from psql shell:
select * from table where userName="xxx";
It gives error:
Error: column "userName" does not exists.
How can I query if column name contain with camelCase.

All identifiers are converted to lower case in postgres. To use upper case identifiers you should use double quotes around identifier to say postgres to not convert it to lower case :
select * from table where "userName" = 'xxx';

Related

What is the exact way of using where clause in PostgreSQL 12? [duplicate]

This question already has answers here:
PostgreSQL "Column does not exist" but it actually does
(6 answers)
sql statement error: "column .. does not exist"
(1 answer)
Postgres column does not exist
(1 answer)
Closed 1 year ago.
I am trying to query a table using where clause in Postgres 12
case 1
SELECT *
FROM schema.e_employee_table
WHERE FK_EMPLOYEE=100;
so when i query the above query i get "FK_EMPLOYEE" column is missing.
case2:
SELECT *
FROM schema.e_employee_table
WHERE "FK_EMPLOYEE"=100;
when i query the above one i got the query results
So can someone explain do we need to put our column name inside "",is it the syntax. If so where it is mentioned in the official documentation.
And I can also see the column name we are mentioning is case sensitive.

I have created a PostgreSQL table but I can't SELECT if I use the WHERE parameter [duplicate]

This question already has answers here:
delete "column does not exist"
(1 answer)
SQL domain ERROR: column does not exist, setting default
(3 answers)
Simple Postgresql Statement - column name does not exists
(2 answers)
Closed 2 years ago.
I am really new at coding in general.
I have created a table but when I try to use SELECT * FROM users WHERE (username = "adminis"); I get ERROR: column "adminis" does not exist. What I am trying to do is to find the user 'adminis' and get the other columns. I have also gone to the documentation but it really does not say a lot.
The table in question:
user_id | username | email | password
---------+----------+-----------------+-----------
1 | adminis | admin#admin.com | ********
Thank you
Double quotes are used for delimiting entity names (if needed), for example:
select *
from "my silly table name with spaces"
Single quotes are used to delimit text. Using your case as an example:
select *
from users
where username = 'adminis'

Inserting values into a table not working [duplicate]

This question already has answers here:
INSERT COMMAND :: ERROR: column "value" does not exist
(2 answers)
Error "value" does not exist - postgresql INSERT INTO issue
(1 answer)
Why does Postgres say column does not exist? [duplicate]
(1 answer)
PostgreSQL - insert statement error, thinks value to insert is a column name
(1 answer)
Closed 3 years ago.
I am trying to insert a value(row) into my table users but it's giving error that column doesn't exist.
User table:
users
insert into users (id,name,gender,city,age,company)
values (1,omkar,"male","cuttack",24,"tcs");
I am getting column does not exists. And with some specific values I am getting hint don't know why.
Error screenshot
You must use single quotes for literal string values. Double quoting is interpreted as being an identifier, in this case a column name, which causes the error.
insert into users (id,name,gender,city,age,company)
values (1,'omkar','male','cuttack',24,'tcs');
If you set "Id" is auto increase, you can try bellow
insert into users (name,gender,city,age,company) values ('omkar','male','cuttack',24,'tcs');

postgres select all not working [duplicate]

This question already has an answer here:
Why can't I see the column names of a table?
(1 answer)
Closed 4 years ago.
I am trying to do a select all on my postgresql table with psql and I am getting a relation does not exist error even though when I run \dt the table clearly does exist. When I enter \d I get:
public | OwnershipDocument | table | iswdp
public | OwnershipDocument_id_seq | sequence | iswdp
When I enter:
select * from OwnershipDocument;
I get:
ERROR: relation "ownershipdocument" does not exist
LINE 1: select * from OwnershipDocument;
I have no idea why this is not working. This database was created with the Django ORM.
select * from "OwnershipDocument". You need quotes because of the uppercase characters.

Postgres Syntax requiring extra ' ' and "" around things

So I am reading tutorial online and I am having a weird issue with my database when doing normal queries. So I see the following does not work:
select * from DBS
ERROR: relation "dbs" does not exist
but This works:
select * from "DBS"
When I do this it fails:
select name from "DBS"
ERROR: column "name" does not exist
but this works but doesnt actually return the correct information (it just has name for every row:
select 'name' from "DBS"
name
name
name
Is there some setting on Postgres causing this to happen?
Postgres 9.4.5 (On RDS).
select 'NAME' from "DBS";
?column?
----------
NAME
NAME
NAME
(3 rows)
When I look at select * from "DBS";
NAME
----------
default
matt
matt2
You need to specify the quotes around the table identifier, because the table uses capital letters and was created using quotes.
postgres has some distinctive behavior re: quoting
select 'name' from "DBS"
You are simply selecting the string literal 'name' once for each row in your table.
Postgres is a little unique in that it folds everything to lowercase unless you use " quotes. I suspect you created your database using pgadmin. If you create a database in pgadmin using UPPER case it will create it with UPPER case and then you will be required to use " around the name to access it. Candidly I'd rename the db to lower case and get rid of the quotes, your life will be a lot easier.