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?'
NOT IN condition is basically used to retrieve data from the table by excluding specified values from the column. We can also use the NOT IN condition with not equal and the AND operator in PostgreSQL. We can also write the NOT IN query by using the not equal and the AND operator.
PostgreSQL column does not exist exception occurs when we have used column did not exist in the table or it will occur when the used column name has lower case name and we have used upper case in our query. We can avoid this exception in many ways like double-quote the column name for which column we have to get the exception.
To execute the NOT condition with the select statement in PostgreSQL we need to have select privileges on the table or we need to have super user privileges to execute the NOT IN condition statement.
But avoid … Asking for help, clarification, or responding to other answers. Making statements based on opinion; back them up with references or personal experience. To learn more, see our tips on writing great answers. Not the answer you're looking for? Browse other questions tagged postgresql join select group-by or ask your own question.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With