s.kumar
s.kumar

Reputation: 126

How to add double quotes in table names using postgresql query?

i have migrated the table and schema from oracle to postgresql. schema name and table name both contains double quotes. How to select the table name in the specific schema using psql command i.e

psql -U enterprisedb -d test -c "select count(*) from "HISTORY"."EMP";"

I have tried the following methods:-

psql -U enterprisedb -d test -c "select count(*) from "HISTORY"."EMP";"
psql -U enterprisedb -d test -c "select count(*) from "||HISTORY||"."||EMP||";"
psql -U enterprisedb -d test -c "select count(*) from ""HISTORY"".""EMP"";"

Below are the codes which i have tried:-

psql -U enterprisedb -d test -c "select count(*) from "HISTORY"."EMP";"
psql -U enterprisedb -d test -c "select count(*) from "||HISTORY||"."||EMP||";"
psql -U enterprisedb -d test -c "select count(*) from ""HISTORY"".""EMP"";"

i want psql command to fetch the data .when i am using double quotes its coudln't find the table . How to use the double quotes in the psql command. I can fetch the data while login to the server the select queries works. but i want to use psql command to work and fetch details.

Upvotes: 0

Views: 524

Answers (1)

joop
joop

Reputation: 4503

You could use a here document, which preserves all quotes:


#!/bin/sh
psql -U enterprisedb -d test <<ZZZZ
        select count(*) from "HISTORY"."EMP"
        ;
ZZZZ

Upvotes: 1

Related Questions