RE: Section 4.1.2.7 contains false information - Mailing list pgsql-docs

From Jind?ich Vavru?ka
Subject RE: Section 4.1.2.7 contains false information
Date
Msg-id VI1PR0402MB3933031B1BE923F6CD74576ECB2D0@VI1PR0402MB3933.eurprd04.prod.outlook.com
Whole thread Raw
In response to Re: Section 4.1.2.7 contains false information  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Section 4.1.2.7 contains false information  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-docs

Dear Tom, it works only in psql, it does not work when you talk to the server using postgresql protocol. That is my point.

 

e.g. in the following code the query causes Syntax error (see the text in red). That means it does not work. Interestingly, when I use $4::timestamp or CAST ( $4 as TIMESTAMP ) the syntax error does not occur.

 

// contest.ts

import { Pool } from 'pg' ;

/** Class representing database access */

export class Db {

  /** PG connection pool */

  pool : Pool ;

  constructor() {

    this.pool = new Pool( {user: 'contest_owner', database: 'contest'} ); // database name and owner

  }

...

  /** Create new contest instance record

   *  @param contestId   {string} Identifier of the contest as specified in the contest log format

   *  @param contestName {string} Human readable contest name for software user

   *  @param startUtc    {string} Start date and time of the contest in UTC 'YYYY-MM-DD hh:mm'

   *  @param endUtc      {string} End date and time of the contest in UTC   'YYYY-MM-DD hh:mm'

   *  @param format      {string} Name of the expected log format (Cabrillo, EDI, ADIF, Garlic)

   */

  createContest( contestId: string, periodId: string, contestName : string,

    startUtc: string, endUtc: string, format : string ): Promise<number|undefined> {

      if( !startUtc.match(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(\:\d{2})?$/)) {

        return Promise.reject('Incorrect format of UTC start date and time, should be "YYYY-MM-DD hh:mm[:ss]"');

      }

      if( !endUtc.match(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(\:\d{2})?$/)) {

        return Promise.reject('Incorrect format of UTC end date and time, should be "YYYY-MM-DD hh:mm[:ss]"');

      }

      return this.pool.query(

        "INSERT INTO public.contest (contest_id, period_id, contest_name, start_ts, end_ts, default_format, status ) "

        + "VALUES ($1, $2, $3, TIMESTAMP $4, TIMESTAMP $5, $6, 'NEW' ) RETURNING contest_key",

        [contestId, periodId, contestName, startUtc, endUtc, format]

      ).then( result => { if( result.rowCount > 0 ) { return result.rows[0].contest_key } else { return undefined; } });

  }

  ...

}

 

 

-----Original Message-----
From: Tom Lane <tgl@sss.pgh.pa.us>
Sent: Tuesday, April 9, 2019 5:57 PM
To: jindrich@vavruska.cz
Cc: pgsql-docs@lists.postgresql.org
Subject: Re: Section 4.1.2.7 contains false information

 

PG Doc comments form <noreply@postgresql.org> writes:

> QUOTE:

> The CAST() syntax conforms to SQL. The type 'string' syntax is a

> generalization of the standard: SQL specifies this syntax only for a

> few data types, but PostgreSQL allows it for all types. The syntax

> with :: is historical PostgreSQL usage, as is the function-call syntax.

> UNQUOTE

 

> In fact, this is not 100% true. TIMESTAMP 'string' does not work this way.

 

Looks like it works to me:

 

regression=# select timestamp '2019-04-09 11:49';

      timestamp     

---------------------

2019-04-09 11:49:00

(1 row)

 

If you feel that the documentation is unclear, you need to be clearer about how it's unclear ;-)

 

(Reading between the lines of this complaint and your adjacent one, I kind of suspect that you were trying to use "TIMESTAMP something"

where the something wasn't a literal string constant.  But surely

4.1.2.7 makes it plain that the discussed syntax is for constants.

You might need to read 4.2.9 "Type Casts" instead.)

 

                                                regards, tom lane

pgsql-docs by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Mark a reloption as indexterm
Next
From: Bruce Momjian
Date:
Subject: Re: asynchronous commit risk window is overly optimistic