Solved

put ' '   inside  ' '   in sql (postgres)   php statement

Posted on 2016-10-27
3
94 Views
Last Modified: 2016-10-28
SELECT
public.pong8_maintable.stockid,
public.pong8_maintable.filname,

date_trunc('hour', public.pong8_maintable."timestamp8") as Date_hour,

public.pong8_maintable."Turnover"
FROM
public.pong8_maintable

Open in new window


The code above is work

But when in php  - Postgres it not work
$sql ='

CREATE TABLE pong8_StepOneSection as
SELECT
public.pong8_maintable.stockid,
public.pong8_maintable.filname,

date_trunc('hour', public.pong8_maintable."timestamp8") as Date_hour,


public.pong8_maintable."Turnover"
FROM
Public.pong8_maintable

' ;

Open in new window

date_trunc('hour', public.pong8_maintable."timestamp8") as Date_hour,       , how can I  change 'hour'
0
Comment
Question by:teera
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 41863663
Try using HEREDOC notation.
http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

I don't know if the PostGreSQL syntax is right, but this works well for the PHP side of things!
$sql = <<<END

CREATE TABLE pong8_StepOneSection as
SELECT
public.pong8_maintable.stockid,
public.pong8_maintable.filname,

date_trunc('hour', public.pong8_maintable."timestamp8") as Date_hour,


public.pong8_maintable."Turnover"
FROM
Public.pong8_maintable

END;

Open in new window

0
 
LVL 17

Accepted Solution

by:
Chris Harte earned 250 total points
ID: 41864007
What Ray said, Or... just escape the quotes on the hour

date_trunc(\'hour\', public.pong8_maintable."timestamp8") as Date_hour,

Open in new window

0
 

Author Closing Comment

by:teera
ID: 41864860
Thank you
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Showing multiple maps using PHP and Google Maps 12 41
Checking https returns 301 21 58
Inserting results of While loop to sql server 5 38
Make login page safer 3 32
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question