tee tee - 1 month ago 8
MySQL Question

Try to put single quote inside single quote postgresql php

this sql I tested it work

SELECT
public.pong8_maintable.stockid,

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

public.pong8_maintable."Turnover"
FROM
public.pong8_maintable


This line does not work when I delete this line
date_trunc("'"hour"'", public.pong8_maintable."timestamp8") as Date_hour,
code will 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 ' ;

sc_exec_sql($sql);


How can I fix it please suggest

Answer

I think this will 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 ' ;

sc_exec_sql($sql);

Some tips:

1) Don't have define like if we have used SINGLE quote sowe have to use it all over .

Example echo 'Hi' and echo "Hi" are same

Reference : date_trunc('hour', public.pong8_maintable."timestamp8") as Date_hour, Here it doesn't matter if you change quote for HOUR from single to double.

2) Third type of qoute ( ` )! Yes, there is 3rd type of quote but i am really not sure about do it work for non-sql statements but within SQL statement id do work.

Comments