Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-3171

LP:881710 - Column name PID returns NULL when called via SP

    Details

    • Type: Bug
    • Status: Closed
    • Resolution: Incomplete
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:

      Description

      I have a very simple table like this:

      CREATE TABLE `path` (
      `PID` int(10) unsigned NOT NULL,
      `PPath` varchar(2000) NOT NULL,
      `PHash` binary(16) NOT NULL,
      PRIMARY KEY (`id`)
      ) ENGINE=InnoDB;

      And a SP:

      create procedure test(path VARCHAR(2000))
      begin

      DECLARE pid INT UNSIGNED;
      DECLARE hash BINARY(16) DEFAULT UNHEX(MD5(path));

      SELECT PID FROM path LIMIT 1;

      end|
      call test("/")|

      Calling the procedure test() returns NULL. Upper and lower case doesn't matter. Renaming the column to something different like

      alter table path change PID id int unsigned;

      returns the correct result.

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            elenst Elena Stepanova added a comment -

            Re: Column name PID returns NULL when called via SP
            Hi,

            Is it still a problem?

            From what I see in your code, you redefine pid in your procedure (without assigning a value to it), so PID in the SELECT is the variable name, not the column name. When you rename the column into something else, it is not masked any longer, so a value from the table is returned. Alternatively, you could provide the full name in SELECT (SELECT path.PID FROM path LIMIT 1).

            Do you have a reason to expect different behavior?

            Show
            elenst Elena Stepanova added a comment - Re: Column name PID returns NULL when called via SP Hi, Is it still a problem? From what I see in your code, you redefine pid in your procedure (without assigning a value to it), so PID in the SELECT is the variable name, not the column name. When you rename the column into something else, it is not masked any longer, so a value from the table is returned. Alternatively, you could provide the full name in SELECT (SELECT path.PID FROM path LIMIT 1). Do you have a reason to expect different behavior?
            Hide
            ratzpo Rasmus Johansson added a comment -

            Launchpad bug id: 881710

            Show
            ratzpo Rasmus Johansson added a comment - Launchpad bug id: 881710

              People

              • Assignee:
                Unassigned
                Reporter:
                robert Robert
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: