practical-sql-2 icon indicating copy to clipboard operation
practical-sql-2 copied to clipboard

Chapter 4 - Listing 4.2

Open pfortin opened this issue 2 years ago • 2 comments

Using PostgreSQL 15.3... Nits which may confuse real beginners... Listing 4.2 could use a "DROP TABLE IF EXISTS number_data_types;", or a different name to avoid table already exists error.

The INSERT enters the numbers as expected; but: SELECT * FROM number_data_types; displays:

 0.70   0.7   0.7
 2.14  2.14  2.14
 2.14  2.14  2.14

instead of the full digits. I see the same output in SQL-workbench/J's Data Explorer Data view... Found SQL-workbench/J setting: Tools>Options...>Data formatting: Decimal digits 2 caused the above output.

pfortin avatar Aug 28 '23 13:08 pfortin

Hi, thanks for filing this.

I took a look. Using both pgAdmin 4 and the psql command-line utility on PostgreSQL 15.3 on macOS, I see the following output that matches the book:

In pgAdmin:

Screen Shot 2023-09-16 at 8 26 32 AM

In psql:

Screen Shot 2023-09-16 at 8 27 47 AM

Those two tools are what the book supports. Now, for the heck of it, I tried the query in DataGrip, which produces:

Screen Shot 2023-09-16 at 8 44 24 AM

So, I'm curious which OS and GUI you're using.

In terms of adding a DROP TABLE statement, I'm not sure that's necessary because we only create the table once in the book. (As far as I remember this early in the morning.) I didn't feel it was worth it to add such a statement to every CREATE in the book. Glad to hear another perspective.

anthonydb avatar Sep 16 '23 12:09 anthonydb

Hi Anthony, Thanks for your response.

OS: Linux Mageia 9 https://www.mageia.org/en/ GUI: SQL Workbench/J https://www.sql-workbench.eu/ Using this because the Mageia team have been unable to provide a working pgAdmin -- tried installing from source and ran into dependency issues.

INSERT: The different output I saw caused me to dig into the "why"... As indicated: "Found SQL-workbench/J setting: Tools>Options...>Data formatting: Decimal digits 2 caused the above output."; so GUI settings may result in output that looks different. While minor, I'm detail oriented, so I had to find the source of the difference... :)

DROP TABLE: I'm going to have to assume I may have issued the CREATE TABLE, taken a break and repeated it later. Sorry for that noise.

pfortin avatar Sep 19 '23 20:09 pfortin