Python Forum
How Does pyspark deal with Spaces in Queries
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How Does pyspark deal with Spaces in Queries
#1
Hello community,

Can someone let me know how pyspark.sql deals with spaces?

For example the following query won't work:

myresults = spark.sql("""SELECT  Name AS [Product Name] FROM Production_vProductAndDescription""")
As you can see above the I have tried to concantenate Product Name with square brackets, but I get error:

Error:
== SQL == SELECT Name AS [Product Name] FROM Production_vProductAndDescription ----------------^^^
However, with no spaces between Product and Name (without the square brackets as follows it works:

myresults = spark.sql("""SELECT  Name AS Product_Name FROM Production_vProductAndDescription""")
Any thoughts welcomed

Cheers

Carlton
Reply
#2
I believe this is the same issue as I said in your other thread. It seems like you're used to MSSQL or something and are now using MySQL, Postgres, or something else with a different SQL dialect than you're used to. I don't think this is PySpark-specific.
Reply
#3
hi micseydel,

The answer is to change [Product Name] to Product Name

Thanks anyway for reaching out.

Cheers
Reply
#4
I understand that. That's consistent with what I'm saying. It's the SQL dialect, not PySpark. I've dabbled with MSSQL, I've never seen the syntax you're trying to use. You need to identify the dialect of the database you're using and familiarize yourself with it, or you're going to hit a great deal of blockers like this.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need to change connection and queries from SQLite to MySQL Bxapocalypse1 2 1,300 Oct-20-2025, 11:35 PM
Last Post: Pedroski55
  Too many queries? lorasf 6 3,127 Jul-04-2023, 04:27 AM
Last Post: lorasf
  PySpark Coding Challenge cpatte7372 4 10,910 Jun-25-2023, 12:56 PM
Last Post: prajwal_0078
  Pyspark dataframe siddhi1919 3 2,883 Apr-25-2023, 12:39 PM
Last Post: snippsat
  pyspark help lokesh 0 1,591 Jan-03-2023, 04:34 PM
Last Post: lokesh
  How to iterate Groupby in Python/PySpark DrData82 2 4,741 Feb-05-2022, 09:59 PM
Last Post: DrData82
  PySpark Equivalent Code cpatte7372 0 2,128 Jan-14-2022, 08:59 PM
Last Post: cpatte7372
  Pyspark - my code works but I want to make it better Kevin 1 2,850 Dec-01-2021, 05:04 AM
Last Post: Kevin
  pyspark parallel write operation not working aliyesami 1 2,904 Oct-16-2021, 05:18 PM
Last Post: aliyesami
  pyspark creating temp files in /tmp folder aliyesami 1 8,383 Oct-16-2021, 05:15 PM
Last Post: aliyesami

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020