Here is a very interesting problem I found.
Here is a snapshot of my table
majorversions Table
Now I try to execute a simple select statement
select * from majorversions mav
where mav.name = "Default-Media"
It throws an error
********** Error **********
ERROR: column "Default-Media" does not exist
SQL state: 42703
Character: 53
It is happening mainly due to the fact that name columnType is Text, if I user client_id in where clause everything works fine.
So how to write a where clause with name as the Column?
Use single quotes for strings.
If it's encased in double quotes it'll think it's a column name and it can't find that column. Thats why you're getting that error.
It should be:
select * from majorversions mav
where mav.name = 'Default-Media'
What it tries to execute in your query is:
select * from majorversions mav where mav.name = mav.Default-Media
Default-Media should be written 'Default-Media' and not "Default-Media"
Related
Every solution I see has to do with people having case sensitive column names.
The query select * from users works, but when I say select * from users where username=maxspiri, I get error column maxspiri doesn't exist. Here is my table:
Since maxspiri is a string, you need to wrap it in single quotes.
select * from users where username='maxspiri'
I am trying to query from a table within a copy command however, I have continually gotten errors. Here is the example SQL statement.
copy schema.table
from 's3://bucket/folder`
iam_role (select value from roles.iam where key = 'IAMRole');
The inner select statement on its own returns a value however, when I run the above, I get the following error:
SQL Error [500310] [42601]: [Amazon](500310) Invalid operation: syntax error at or near "("
The COPY command, as you must suspect, does not support embedded SQL.
If you want to do something like this, you can, but you'll need a procedure.
I am trying to run an update command on postgresql 11.6 by below syntax
update "YP_SUPPLIERS" set "YP_SUPPLIERS.supplierName" = "update" where "YP_SUPPLIERS.supplierID" = da68e9d0-1100-43e2-0011-db8fbe654321;
I am getting this below error
ERROR: column "YP_SUPPLIERS.supplierID" does not exist
LINE 1: ... set "YP_SUPPLIERS.supplierName" = "update" where "YP_SUPPLI...
tired different combinations by only giving the column name , removing the quotes but nothing seems to be working.
Could any one suggest me a right way to do it.
You need to quote each element separately, and the table does not need to be repeated for the target column. String constants need to be enclosed in single quotes (') in SQL. Double quotes are only for identifiers.
update "YP_SUPPLIERS"
set "supplierName" = 'update' --<< single quotes for constant values
-- ^ no table name here
where "YP_SUPPLIERS"."supplierID" = 'da68e9d0-1100-43e2-0011-db8fbe654321';
-- ^ schema and table name must be quoted separately
%sql select Name_of_School, Safety_Score from SCHOOLS where \
Safety_Score= (select MAX(Safety_Score) from SCHOOLS)
i am trying to execute this query i got the message.
ibm_db_sa://rbm44299:***#dashdb-txn-sbox-yp-lon02-04.services.eu-gb.bluemix.net:50000/BLUDB
(ibm_db_dbi.ProgrammingError) ibm_db_dbi::ProgrammingError: SQLNumResultCols failed: [IBM][CLI Driver][DB2/LINUXX8664] SQL0206N "SAFETY_SCORE" is not valid in the context where it is used. SQLSTATE=42703 SQLCODE=-206
[SQL: select Name_of_School, Safety_Score from SCHOOLS where Safety_Score= (select MAX(Safety_Score) from SCHOOLS)]
(Background on this error at: http://sqlalche.me/e/f405)
SQL0206N is this error message https://www.ibm.com/support/knowledgecenter/SSEPGG_11.5.0/com.ibm.db2.luw.messages.sql.doc/com.ibm.db2.luw.messages.sql.doc-gentopic1.html#sql0206n
SQL0206N name is not valid in the context where it is used.
This error can occur in the following cases:
For an INSERT or UPDATE statement, the specified column is not a column of the table, or view that was specified as the object of the insert or update.
For a SELECT or DELETE statement, the specified column is not a column of any of the tables or views identified in a FROM clause in the statement.
among other cases.
I.e. Column SAFETY_SCORE does not exist in your table. Maybe the column is "Safety_Score" or "Safety Score" or some other name.
If the column name is not in UPPER CASE in your table, you will need to surround it in double quotes.
I could fix by using the %%sql structure and the double quotes :
%%sql
select MAX("Safety Score") AS MAX_SAFETY_SCORE from Chicago_SCHOOLS;
I am trying to use PostgreSQL's currval function to return the last inserted row id of a table called Concept. Concept has a serial primary key called cid and there was an automatically generated Sequence called Concept_cid_seq.
I try the following statement and get an error:
SELECT currval("Concept_cid_seq");
ERROR: column "Concept_cid_seq" does not exist
LINE 1: SELECT currval("Concept_cid_seq");
^
********** Error **********
ERROR: column "Concept_cid_seq" does not exist
SQL state: 42703
Character: 16
But when I run the query :
SELECT * from "Concept_cid_seq";
I get a table with one row (as I'd expect) showing columns like last_value, start_value, etc...
What am I missing here? Am I passing the wrong information to currval? Why does it say the 'column does not exist?'
It turns out that this was an issue with capitalization and quotes. Because I wanted to preserve the capitalization of the relation name I needed to use both single and double quotes in order to pass the correct relation name to currval.
I changed the query to SELECT currval('"Concept_cid_seq"'); (note the outer single quotes) and it worked correctly.