Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mCD0X-0007dw-KE for pgsql-general@arkaria.postgresql.org; Sat, 07 Aug 2021 03:28:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mCD0W-0006Ch-Fn for pgsql-general@arkaria.postgresql.org; Sat, 07 Aug 2021 03:28:20 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mCD0W-0006CZ-0v for pgsql-general@lists.postgresql.org; Sat, 07 Aug 2021 03:28:20 +0000 Received: from mail-qt1-x82e.google.com ([2607:f8b0:4864:20::82e]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mCD0T-0002ch-7q for pgsql-general@lists.postgresql.org; Sat, 07 Aug 2021 03:28:18 +0000 Received: by mail-qt1-x82e.google.com with SMTP id k13so8017549qth.10 for ; Fri, 06 Aug 2021 20:28:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=aU8Nx8YcIMd2zfvzsyx+PdDTKpMJpdWcsP6cfFM+BsA=; b=EkNtUsidnvIKNohSI3osblFXtnma1Vsz+3v6KUinoJ8w2o0w1sHSAOllGPXlVYuGXo LRtNouw94eyrD1jtXdPnFlPdJ0janplyZVP/AjgthoUgeMzavxgkn6tIIPm6qNfrOShB BG9Mf9fzMUkv43KwDNLk6MpkCb0Xd4RGVeLNzB7xvysAsl4XTpoOK7y+Sj4dRno74r2F TIp04ObMuvR+ejaO9RxZenaTEvN6rkjR4I/h5mChBjuTVJFF5NeqG7IxSKGkejWKkBzY KUr3O8BLQrRpDwMrHQApS4anC0szvQEO9bJG2gC6lOHcPq9rF4kZenlO4XRsmnTCDNrE Lp0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=aU8Nx8YcIMd2zfvzsyx+PdDTKpMJpdWcsP6cfFM+BsA=; b=oGsoEPyNrsOnNn/b3FQmlwu/GmosO5cs4Df/xEvJukEB7AzNZeQUIfWoJnA6J24WKa oe8buA7JOF13aMKFbziCLkYUg7KoinnfqP1A0b8H1TBHE8/pTyKKnEamvt5H/HM9gepD j15fi0+VG9BYreAHpkFJ+hOQs+VSw83drWBl3qzjTNSDsSgZjJKRNvAArOMFgu3U3rEg gMAfXLGzW12c75uGXoOTbTV39GgYmD7DPgVCE5IMDlN5Pq4pgYnxB+gtP7vwEJT2B6Sm GmFCPZcKr6jkofVNGN8ZxQ6XXtKsry80AxcTr0zH3seZ3Up9XYpBXqcc42oHLK5oF55i yzVQ== X-Gm-Message-State: AOAM532vmrzWFRnwsbSpP11uJv1UXJLoAX0p5MP0URLFNgKEdM+TAerE BnNXFuDkpp7I0InVetiqeQ5qS04IHE3LGw== X-Google-Smtp-Source: ABdhPJzZYyChmuqVKH2YobsuGYAV7U8Wvno57F0Do3H+R+C1wzkHO87cqvT3vWECfUm1Q4fxLANMUQ== X-Received: by 2002:a05:622a:514:: with SMTP id l20mr11566631qtx.215.1628306894449; Fri, 06 Aug 2021 20:28:14 -0700 (PDT) Received: from [192.168.2.100] (pool-100-8-54-81.nwrknj.fios.verizon.net. [100.8.54.81]) by smtp.gmail.com with ESMTPSA id l4sm5666917qkd.77.2021.08.06.20.28.13 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Aug 2021 20:28:14 -0700 (PDT) Subject: Re: Series of 10 questions about the use of postgresql, generally. To: pgsql-general@lists.postgresql.org References: From: Mladen Gogala Message-ID: <49e99685-5b35-1707-e68f-2826bf6d9286@gmail.com> Date: Fri, 6 Aug 2021 23:25:40 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------B0AE4E6095D08EA8E896642B" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------B0AE4E6095D08EA8E896642B Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 8/6/21 1:11 AM, Pavel Stehule wrote: > > 2. If I am using the COPY command for input and output around > *.csv files, how may I specify internal tuple delimiters of > ',', but at the same time also specify an end of line > delimeter of ';' ? > > you cannot to specify end of line delimiter in Postgres You can specify end of line delimiter in Perl, Python or PHP. It is highly advisable to learn a scripting language or two when working with databases. With all databases, not just Postgres. > > 3. How may I get postgresql to output the create table > statement(s) for one or more tables of one database? > > ???? > > 4. I know that I can use COPY to import or export one database > table between it and a *.csv file. Can I use it to do this > with multiple TABLES and *.csv files specified in one COPY > COMMAND, or not? How may I use COPY, or another default native > postgresql function, to export or import create table commands > to and from a *.csv file? > > COPY can be used just for one table in one time > > if you want to make DDL command (CREATE TABLE), then you should to run > pg_dump -t tablename -a > > 5. In the absence of OS command line instructions, is there an > internal postgresql way, via COPY or another function for > example, to backup an entire database, with all its create > table statements and all insert statements, and any other > associated object, in one hit? Or is this ill advised? > > pg_dump > > 6. -How exactly do Intervals work, via themselves and in relation > to the other provided native datatypes? What are Intervals > used for? > > Interval is Postgres native type, that helps with work with date > operations that are not possible to map to some basic unit. Internally > it is a structure with numeric fields - years, months, days, hours, > seconds. For example - I can work with a value '3 months', but without > knowledge of the beginning, I cannot say how many days this interval > has. You can create interval value by constructor function > make_interval, or directly from literal, or you can divide two > timestamp values. > Interval is a SQL standard data type for adding and subtracting dates. It is supported by a gazillion of other databases: https://www.ibm.com/docs/en/informix-servers/12.10?topic=types-sql-datetime-interval-data https://www.mysqltutorial.org/mysql-interval/ https://www.oracletutorial.com/oracle-basics/oracle-interval/ https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types The only major database that does not support the interval type is SQL Server. SQL Server has a major problem with SQL standards. It also doesn't support FETCH  FIRST ROWS ONLY OFFSET syntax. Of course, this group is not about SQL Server so I'll leave it at that. -- Mladen Gogala Database Consultant Tel: (347) 321-1217 https://dbwhisperer.wordpress.com --------------B0AE4E6095D08EA8E896642B Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit


On 8/6/21 1:11 AM, Pavel Stehule wrote:
 
  1. If I am using the COPY command for input and output around *.csv files, how may I specify internal tuple delimiters of ',', but at the same time also specify an end of line delimeter of ';' ?
you cannot to specify end of line delimiter in Postgres

You can specify end of line delimiter in Perl, Python or PHP. It is highly advisable to learn a scripting language or two when working with databases. With all databases, not just Postgres.



  1. How may I get postgresql to output the create table statement(s) for one or more tables of one database?
????
  1. I know that I can use COPY to import or export one database table between it and a *.csv file. Can I use it to do this with multiple TABLES and *.csv files specified in one COPY COMMAND, or not? How may I use COPY, or another default native postgresql function, to export or import create table commands to and from a *.csv file?
COPY can be used just for one table in one time

if you want to make DDL command (CREATE TABLE), then you should to run pg_dump -t tablename -a
 
  1. In the absence of OS command line instructions, is there an internal postgresql way, via COPY or another function for example, to backup an entire database, with all its create table statements and all insert statements, and any other associated object, in one hit? Or is this ill advised?
pg_dump
 
  1. -How exactly do Intervals work, via themselves and in relation to the other provided native datatypes? What are Intervals used for?
Interval is Postgres native type, that helps with work with date operations that are not possible to map to some basic unit. Internally it is a structure with numeric fields - years, months, days, hours, seconds. For example - I can work with a value '3 months', but without knowledge of the beginning, I cannot say how many days this interval has. You can create interval value by constructor function make_interval, or directly from literal, or you can divide two timestamp values.

Interval is a SQL standard data type for adding and subtracting dates. It is supported by a gazillion of other databases:

https://www.ibm.com/docs/en/informix-servers/12.10?topic=types-sql-datetime-interval-data

https://www.mysqltutorial.org/mysql-interval/

https://www.oracletutorial.com/oracle-basics/oracle-interval/

https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types

The only major database that does not support the interval type is SQL Server. SQL Server has a major problem with SQL standards. It also doesn't support FETCH  FIRST <n> ROWS ONLY OFFSET <n> syntax. Of course, this group is not about SQL Server so I'll leave it at that.


-- 
Mladen Gogala
Database Consultant
Tel: (347) 321-1217
https://dbwhisperer.wordpress.com
--------------B0AE4E6095D08EA8E896642B--