Python SQL cursor/fetch: When does the database query complete running?

I had a question regarding the python IBM_DB package (but I think it could be applied to any of the packages that employ the connection/cursor logic i.e. pyodbc).

When the cursor.execute() method is called, it executes an sql query on the database. However, to access this data, you would need to use the fetchall()/other fetch methods. I want to time the hit on the database.

Does the query completely finish running at the execute level, and it is in memory just for python to fetch? Or does the fetch method continue calling the database? I have scoured the documentation and am unable to find anything definitive on this subject.

caml query – using SSRS to generate a report based on a Calendar in Sharepoint 2013

We use the calendar in SP2013 to collect information when a user is away on holiday and when there will be any visitors. It works fine as a calendar but now struggling to generate a report in SSRS to show all the days when on holiday.

Example; this is what calendar looks like in SP2013

enter image description here

I am struggling to show all the consecutive days from Friday 03/02/2017 until 17/02/2017.
In this case, the Reports is just pulling the start date =Fields!Start_Time.Value

enter image description here

enter image description here

As you can see, from the result above, it does not show all the consecutive days but only the start time. Yes, you may say “…well you specified to show from the start time” but my question is here how to modify it so it shows HOLIDAY on all the dates relative to the start & end date.

Any ideas / suggestions?

The SSRS Query Type is as following:

<RSSharePointList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <ListName>Staff Movements</ListName>
  <ViewFields>
    <FieldRef Name="Title" />
    <FieldRef Name="Location" />
    <FieldRef Name="EventDate" />
    <FieldRef Name="EndDate" />
    <FieldRef Name="Category" />
    <FieldRef Name="User" />
    <FieldRef Name="Department" />
    <FieldRef Name="Position" />
    <FieldRef Name="Visitors_x0020_Name" />
    <FieldRef Name="Visitors_x0020_Business" />
    <FieldRef Name="Visitors_x0020_purpose" />
    <FieldRef Name="Visitors_x0020_Visiting" />
    <FieldRef Name="Created" />
  </ViewFields>
</RSSharePointList>

What syntax does PostgreSQL require when all identifiers in a query are dynamic?

Example:

SELECT $1 FROM $2.$3 WHERE $1 = $4

Result:

ERROR:  syntax error at or near "$2"

Example:

SELECT "$1" FROM "$2"."$3" WHERE "$1" = "$4"

Result:

ERROR:  relation "$2.$3" does not exist

If you wonder why all the identifiers are parameterized, it’s because I’m designing a database manager tool which dynamically allows me to edit any “cell” in any table.

wordpress – Set a Google AdWords campaign objective for a URL with a query string

We will launch a Google AdWords campaign for our website.

On our website, we have a page to let users to send us a form for contact. After a user clicks on Envoyer, the page will be redirected to https://example.com/?cf_id=20 (note that the id number in the end may change)

My colleague wants to set a campaign objective for this clicking of Envoyer. Does anyone know if it is possible to set an objective for that (e.g., a URL with a query cf_id)?

PS: Our website is built with WordPress and the form is built with calderaforms.com

information schema – How to use a query to get the definition of MySQL database objects (specifically the variables they use)

I have written a query to get most of the useful information about the routines in a MySQL database for a database documenter that I am developing.

The code below will return routine name, routine type, routine param list, routine return value (if any), routine definition and routine comment (if any).

However I can’t seem to work out how to return any variables that are used by each routine (either local or session)

Can anyone help me out with the code to get that extra column displayed in my query with the variable names in it?
(Be good if they were concatenated as I have done with the parameters but that’s not too important.)

I would stress that the databases are held on a remote shared server so I cannot log in as root, nor can I access it as local host. ie for example, access to tables like ‘proc’ and ‘users’ and others that would be available to an admin user are denied

The code I have so far that returns most of the information (also included in case it’s useful to anyone else)

SELECT routine_name, routine_type, routine_param_list,routine_returns,routine_body, routine_comment FROM (

SELECT
  
    `information_schema`.`events`.`EVENT_NAME` AS `routine_name`,
    'EVENT' AS `routine_type`,
    '' AS `routine_param_list`,
    '' AS `routine_returns`,
    `information_schema`.`events`.`EVENT_DEFINITION` AS `routine_body`,
    `information_schema`.`events`.`EVENT_COMMENT` AS `routine_comment`

  FROM
    `information_schema`.`events`
   
    
    
  UNION
  ALL
  
  SELECT
   
    `information_schema`.`routines`.`ROUTINE_NAME` AS `routine_name`,
    `information_schema`.`routines`.`ROUTINE_TYPE` AS `routine_type`,
    (SELECT
      GROUP_CONCAT(
        CONCAT(
          `information_schema`.`parameters`.`PARAMETER_MODE`,
          ' ',
          `information_schema`.`parameters`.`PARAMETER_NAME`,
          ' ',
          `information_schema`.`parameters`.`DTD_IDENTIFIER`
        ) SEPARATOR '; '
      )
    FROM
      `information_schema`.`parameters`
    WHERE `information_schema`.`parameters`.`SPECIFIC_NAME` = `information_schema`.`routines`.`ROUTINE_NAME`
    GROUP BY `information_schema`.`parameters`.`SPECIFIC_NAME`) AS `routine_param_list`,
    `information_schema`.`routines`.`DTD_IDENTIFIER` AS `routine_returns`,
    `information_schema`.`routines`.`ROUTINE_DEFINITION` AS `routine_body`,
    `information_schema`.`routines`.`ROUTINE_COMMENT` AS `routine_comment`

  FROM
    `information_schema`.`routines`
   

    UNION
    ALL
    
    (SELECT
      
      `information_schema`.`tables`.`TABLE_NAME` AS `routine_name`,
      `information_schema`.`tables`.`TABLE_TYPE` AS `routine_type`,
       NULL AS `routine_param_list`,
      '' AS `routine_returns`,
       CONCAT(
        'Algorithm: ',
        `information_schema`.`VIEWS`.`ALGORITHM`,
        CHAR(13),
        CHAR(10),
        CHAR(13),
        CHAR(10),
        `information_schema`.`VIEWS`.`VIEW_DEFINITION`
      ) AS `routine_body`,
      '' AS `routine_comment`

    FROM
      (
        `information_schema`.`tables`
        LEFT JOIN `INFORMATION_SCHEMA`.`VIEWS`
          ON (
            `information_schema`.`VIEWS`.`TABLE_NAME` = `information_schema`.`tables`.`TABLE_NAME`
          )
      )
    WHERE `information_schema`.`tables`.`TABLE_TYPE` = 'VIEW'
   )
    
    ) AS T
    
--   where routine_name = 'MyRoutine'
--    and routine_type = 'MyRouitineType'

postgresql – Is it possible to reduce the duplication in this simple query?

I’m new to SQL and so this is probably a stupid question but can I reduce the duplication in this query? My actual query involves more complex expressions. Right now I’m just doing string concatenation from the language I’m using to generate the long query but I think there must be a way to do this with plain SQL?

select
  x + y as a,
  x + z as b,
  (x + y) / (x + z) as c
from
  integers
order by
  z + (x + y) / (x + z) desc
limit
  10;

What I’d like:

select
  x + y as a,
  x + z as b,
  a / b as c
from
  integers
order by
  z + c desc
limit
  10;

-- Fails with: Query Error: error: column "a" does not exist

Sample table:

create table integers as
select x, y, z
from
  generate_series(1, 10) x,
  generate_series(x, 10) y,
  generate_series(y, 10) z;

Fiddle: https://www.db-fiddle.com/f/u3cVh7QsafWNE6ELWhvBc1/0

Query to get count of inserted records hourly wise in postgresql?

Postgres can truncate a date to a certain precision:

SELECT DATE_TRUNC('hour', creation_date) FROM demo

So all you have to do is group and count it:

SELECT DATE_TRUNC('hour', creation_date), COUNT(*) 
FROM demo 
GROUP BY DATE_TRUNC('hour', creation_date)

formulas – How to reference a cell outside range using query function in Google Sheets

I’m trying to copy cells B to F to another sheet if the text in cell J contains specific text. As an example case, I’m using the query function as:

=query('Sheet 1'!B1:J,"Select * Where J contains 'Apples'") 

and that works fine, but I don’t want all cells B to J to be copied across, just cells B to F.

mysql – what is the difference between first and second execution of a query?

I notice that when I am executing queries the first time (i.e., just after mysqld_safe --user=mysql &), the queries are slower than when they are executed second time. When the query (source) is:

select 
    s_name, s_address 
from 
    SUPPLIER, NATION 
where 
    s_suppkey in ( 
        select 
            ps_suppkey 
        from 
            PARTSUPP 
        where 
            ps_partkey in (
                select 
                    p_partkey 
                from 
                    PART 
                where 
                    p_name 
                like 
                    'green%'
            ) and 
            ps_availqty > (
                select 
                    0.5 * sum(l_quantity) 
                from 
                    LINEITEM 
                where 
                    l_partkey = ps_partkey and 
                    l_suppkey = ps_suppkey and 
                    l_shipdate >= date '1993-01-01' and 
                    l_shipdate < date '1993-01-01' + interval '1' year
            )
    ) and 
    s_nationkey = n_nationkey and 
    n_name = 'ALGERIA' 
order by 
    s_name;

And I got:

> SELECT .....;
>   41.255s # <-------- first time
> SELECT .....;
>   6.242s # <-------- second time
> SELECT .....;
>   6.104s # <-------- third time

However, in some other times, the difference does not exist. For example, this query(source):

SELECT 
    s_name, count(*) as numwait 
FROM 
    SUPPLIER, LINEITEM l1, ORDERS, NATION 
WHERE 
    s_suppkey = l1.l_suppkey and 
    o_orderkey = l1.l_orderkey and 
    o_orderstatus = 'F' and 
    l1.l_receiptdate > l1.l_commitdate and 
    exists ( 
        SELECT * 
        FROM LINEITEM l2 
        WHERE 
            l2.l_orderkey = l1.l_orderkey and 
            l2.l_suppkey <> l1.l_suppkey
    ) and 
    not exists (
        SELECT * 
        FROM LINEITEM l3 
        WHERE 
            l3.l_orderkey = l1.l_orderkey and 
            l3.l_suppkey <> l1.l_suppkey and 
            l3.l_receiptdate > l3.l_commitdate
    ) and 
    s_nationkey = n_nationkey and 
    n_name = 'EGYPT' 
GROUP BY 
    s_name
ORDER BY 
    numwait desc, s_name 
LIMIT 100;

I got:

> SELECT .....;
>   3m9.264s # <-------- first time
> SELECT .....;
>   3m9.377s # <-------- second time
> SELECT .....;
>   3m7.287s # <-------- third time

MySQL version is 8.0.22
All configurations are default.

Why it is the case?

Thanks.

H1b – DS160 PREVIOUS EMPLOYMENT SECTION QUERY

My husband has drop box appointment for H1b. I have a question regarding the DS160 PREVIOUS EMPLOYMENT section. We realized that the Employer address(at the bottom of the page) in his I797 does not match with my actual work location. It was a different branch office’s address. So, in the DS160, should we enter his actual work location or the address specified in I797?