Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Omitting the double quote to do query on PostgreSQL

Simple question, is there any way to omit the double quote in PostgreSQL?

Here is an example, giving select * from A;, I will retrieve ERROR: relation "a" does not exist, and I would have to give select * from "A"; to get the real result.

Is there any way not to do the second and instead do the first on PostgreSQL?

like image 405
zfm Avatar asked Jun 13 '11 14:06

zfm


People also ask

How do I escape double quotes in PostgreSQL?

Quotes and double quotes should be escaped using \.

How do I ignore a double quote in SQL?

Use two single quotes to escape them in the sql statement. The double quotes should not be a problem: SELECT 'How is my son''s school helping him learn? "Not as good as Stack Overflow would!"'

Does PostgreSQL allow double quotes?

In PostgreSQL, double quotes (like "a red dog") are always used to denote delimited identifiers. In this context, an identifier is the name of an object within PostgreSQL, such as a table name or a column name. Delimited identifiers are identifiers that have a specifically marked beginning and end.

How do I select a single quote in PostgreSQL?

select E 'Text\'Text'; Explanation: In the above syntax, we use a select statement but this syntax is applicable for old versions of PostgreSQL string constants with E and backslash \ to escape single quotes.


1 Answers

Your problem with this query started when you created your table. When you create your table, don't use quotes.

Use this:

CREATE TABLE a ( ... ); 

Not this:

CREATE TABLE "A" ( ... ); 

The latter will make it so that you always have to quote it later. The former makes it a normal name and you can use SELECT * FROM a; or SELECT * FROM A;

If you can't just recreate your table, use the ALTER TABLE syntax:

ALTER TABLE "A" RENAME TO a; 
like image 125
Steve Prentice Avatar answered Oct 02 '22 18:10

Steve Prentice