anthonydb / practical-sql-2

Code and Data for the Second Edition of "Practical SQL" by Anthony DeBarros, published by No Starch Press (2022).
Other
502 stars 441 forks source link

Chapter 4 - Listing 4.2 #17

Closed pfortin closed 2 weeks ago

pfortin commented 1 year ago

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.

anthonydb commented 1 year ago

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.

pfortin commented 1 year ago

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.