Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9212065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:26:26+00:00 2026-06-18T01:26:26+00:00

I am new to postgres and I play around with data loading. Here is

  • 0

I am new to postgres and I play around with data loading.
Here is the table definition from postgres 9.2 spec:

CREATE TABLE weather (
    city varchar(80),
    temp_lo int, -- low temperature
    temp_hi int, -- high temperature
    prcp real, -- precipitation
    date date
 );

I prepared the following data file (weather.txt):

San Francisco   43  57  0.0 '1994-11-29'
Hayward 54  37  0.0 '1994-11-29'

and ran the COPY command:

COPY weather FROM '~aviad/postsgres/playground/weather.txt';

now, when I run select * from weather; I see that single quotes appears around the city values.
This does not happen when I run simple INSERT e.g:

INSERT INTO weather VALUES ('San Francisco', 46, 50, 0.25, '1994-11-27');

I wonder:

  1. what is the reason for wrapping text values by single quotes?
  2. What is the correct way to put the text data in the file used by
    COPY to avoid single quote wrapping?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:26:28+00:00Added an answer on June 18, 2026 at 1:26 am

    What you describe in your question is obviously not what’s really happening. COPY would fail trying to import string literals with redundant single quotes into a date column.

    To get rid of redundant quotes, import to a temporary table with text column, then INSERT INTO the target table trimming the quotes:

    CREATE TEMP TABLE wtmp (
       city text
     , temp_lo int
     , temp_hi int
     , prcp real
     , date text  -- note how I use text here.
    );
    
    COPY wtmp FROM '~aviad/postsgres/playground/weather.txt';
    
    INSERT INTO weather (city, temp_lo, temp_hi, prcp, date)
    SELECT city, temp_lo, temp_hi, prcp, trim(date, '''')::date
    FROM   wtmp
    -- ORDER BY ?
    ;
    

    The temp table is dropped automatically at the end of your session.

    Reserved words as identifiers

    I see you copied the example from the manual. Here is the deep link to the current manual.

    While being correct, that example in the manual is unfortunate. I’d advise not to use reserved words like date as column names. As you can see here date is a reserved word in every SQL standard. It’s allowed to use in Postgres and I can see how it’s tempting for a simple example. But that doesn’t make it a good idea. Generally, you should be in the habit of avoiding reserved words as identifiers. It leads to confusing error messages and needlessly incompatible SQL code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a new table in postgres but when I do it
i am new to java, i am trying to insert a data from old_db
I want to create a Postgres Stored function in plpgsql that creates a table
Did a new install of postgres 8.4 on mint ubuntu. How do I create
i'm quite new to postgres. i want to create a function (like stored procedure)
I'm using JPA with a postgres DBMS and I'm trying to create a new
I have the following table in postgres: CREATE TABLE test ( id serial NOT
I have a migration that runs an SQL script to create a new Postgres
In postgres 9.2 i have a column with a timestamp CREATE TABLE pilot (
For a new project I'm trying to run postgres locally. Mac Lion has Postgres

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.